Game Development Community

Dynamicaly create child gui object from script.

by Peterjohn Griffiths · in Torque Game Engine · 09/15/2006 (6:55 am) · 5 replies

Hi,
I am creating a Network Lobby for my driving game and will be releasing it as a resource when finished.
I have come across a small problem I don't know how to resolve.
When people join a server they join the network lobby and can chat and then click a check box when ready to play.
I have the chat all worked out but I am having problems with the Player List.
I have a guiScrollCtrl called NetworkLoungePlayerList and I want to add each player to it when they join the server.
1st, I want to add a guiMLTextCtrl with their player name and 2nd add a guiCheckBoxCtrl next to it.
The problem I have is I need to create these dynamicaly through script as child objects of the guiScrollCtrl called NetworkLoungePlayerList.
Here is the code I have but it doesn't create them as child objects.
function NLAddPlayer(%PlayerName)
{
	NLAddPlayerName(%PlayerName);
}

function NLAddPlayerName(%PlayerName){
   new GuiMLTextCtrl("NLPlayerListText" @ %PlayerName) { //Name the gui object.
      Profile = "GuiMLTextProfile";
      text = %PlayerName;
      HorizSizing = "relative";
      VertSizing = "relative";
      position = "2 2";
      Extent = "376 52";
      MinExtent = "8 2";
      Visible = "1";
      Variable = "";
      lineSpacing = "2";
      allowColorChars = "0";
      maxChars = "-1";
   };
}

function NLAddPlayerReadyCheckbox(%PlayerName){
   new GuiCheckBoxCtrl("NLPlayerListCheckbox" @ %PlayerName) {
      Profile = "GuiCheckBoxProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "305 4";
      Extent = "72 30";
      MinExtent = "8 2";
      Visible = "1";
      text = "Button";
      groupNum = "-1";
      buttonType = "ToggleButton";
   };
}

Many thanks in advance for any help you can give me.
Pejayuk.

#1
09/15/2006 (7:10 am)
Of course it doesn't. You need to manually add the objects you created to the gui object you want. Every gui object can act as a group and you can add objects to them.
#2
09/15/2006 (7:18 am)
Thats what I want to do but through script. The above works as far as it creates the object but how do you add the object through script as a child of another gui object.
#3
09/15/2006 (8:06 am)
parent.add(child);

That's the syntax.
#4
09/15/2006 (8:23 am)
Thank you Manoel Neto. That works a treat.
I have been looking at this for hrs, banging my head against the wall so to speak.
Just need to add some position code and its away.
Many thanks again.
#5
09/15/2006 (10:48 am)
Use a debug build and call dump() on any object from the console, and you'll get a nice list of all methods avaliable for them.