Game Development Community

Creating/removing a new GuiControl in-game.

by Phil Mundy · in Torque Game Engine · 08/13/2006 (9:58 am) · 11 replies

Hey, I want to be able to create a new GuiControl during the game. I need it to be able to be actually created rather than just initially made, then switched between visible and invisible.

In a script file function I wrote:

new GuiControl(Note) {
		profile = "GuiDefaultProfile";
		horizSizing = "right";
		vertSizing = "bottom";
		position = "100 100";
		extent = "100 100";
		minExtent = "8 2";
		visible = "1";
		groupNum = "-1";
	};

And when the function is run, I can then retrieve data from "Note" but it is not in the GUI Editor's list on objects or at all selectable or visible. I imagine I have to add it as a child to my main PlayGui or something...

Any ideas?

#1
08/13/2006 (10:01 am)
To add & remove a GUI file via script:

PlayGui.add(Note);
PlayGui.remove(Note);

- Tim
#2
08/13/2006 (10:03 am)
Gah! So Simple.

Thanks.
#3
08/13/2006 (10:04 am)
To set visible, invisible:

note.visible = 0;
note.visible = 1;

- Tim
#4
08/13/2006 (10:06 am)
Another variation on the visible / invisible cmd:
note.setVisible(true);
note.setVisible(false);

- Tim
#5
08/13/2006 (10:08 am)
While I'm here and having trouble sleeping here's some more generic script GUI cmds:
Canvas.popDialog(myGui);
Canvas.pushDialog(myGui);
Canvas.setContent(myGui);
myGui.setValue(value);
myGui.setBitmap(bitmap);

- Tim
#6
08/13/2006 (5:05 pm)
All my GUIS get content populated everytime the GUI becomes visible... depending on what you're doing you may end up with the GUI controls out of Z-Order... if this becomes an issue....

www.garagegames.com/mg/forums/result.thread.php?qt=17288

That's a perfect fix and i love it so.
#7
08/13/2006 (5:08 pm)
Fwiw, i'd recommend Tim's seconds visible/invisible example over the first.

a good general rule is that anytime there's a setter/getter for something which also has raw variable-access,
use the setter/getter.
#8
08/14/2006 (7:14 am)
Thanks folks, anyone know how to rename a Gui dynamically after its been created?
#9
08/14/2006 (8:01 am)
SetName() dude.

if you haven't downloaded this, you might consider it. it's a lot faster than asking the forums.
#10
08/14/2006 (8:12 am)
Thanks dude. They should tell you things like this at the beginning. There's so many clueless people like me.
#11
08/14/2006 (8:50 am)
True dat.

another handy thing is the dump() method,
which nearly every SimObject supports, GuiControls included.

eg

%myControl.dump()

dumps a list of member fields and methods.

- it doesn't show the children controls, but it really ought. that would be a fairly simple mod to SimSet, i think.