Game Development Community

Access sub GUI in script???

by John Eric Miller · in Torque Game Engine · 07/11/2005 (3:51 pm) · 11 replies

From the folowing code how would I set the GuiBitmapCtrl to visible?

I would assume I could use Picture1.setVisible(1); but I get an error in script saying the object doesn't exist. I know this code is being executed because I can see the picture on the screen when I change the script for the picture to be visible.

Is there special syntax to get at a sub GUI object?

new GameTSCtrl(PlayGui) {
profile = "GuiContentProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "0 0";
extent = "640 480";
minExtent = "8 8";
visible = "1";
helpTag = "0";
noCursor = "1";

new GuiBitmapCtrl(Picture1) {
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "620 5";
extent = "15 15";
minExtent = "15 15";
visible = "0";
helpTag = "0";
bitmap = "./HeartLight25.png";
wrap = "0";
};
};

#1
07/11/2005 (3:57 pm)
I figured out my issue. For some reason my code works now. I must have been doing something stupid. Anyway I have another GUI related question. Is there a method for setting the bitmap property at runtime? Can dynamically create bitmap controls using a loop and give the bitmap controls names that I can access through script?
#2
07/11/2005 (4:44 pm)
Have you tried using dump() on the objects in question to find out?
#3
07/11/2005 (5:18 pm)
Awesome, thanks!

What about my dynamic question?
#4
07/11/2005 (6:16 pm)
Did using .dump(); on your GUI give you a function called "setBitmap"?
#5
07/11/2005 (8:24 pm)
Yes, but I had a 2nd question.

Can I dynamically create bitmap controls using a loop and give the bitmap controls names that I can access through script? or access them through some type of array or collection?

Thanks!
#6
07/11/2005 (9:29 pm)
Yup. Just spawn them like they're spawned in .gui files. :o

Example:
function makepictures(%count)
{
for(%i = 0; %i < %count; %i++)
{
$Picture[%i] = new GuiBitmapCtrl("Picture"@%i) {// give it name, too
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = gerRandom(640) SPC getRandom(480);// somewhere random
extent = "15 15";
minExtent = "15 15";
visible = "0";
helpTag = "0";
bitmap = "./HeartLight25.png";
wrap = "0";
};
}
}
#7
07/12/2005 (7:15 pm)
Thanks Josh! You are the man!

I didn't know you could name objects like that in script. I really appreciate the help!
#8
07/13/2005 (12:57 pm)
I have another GUI question or more a script syntax question.

I used the example you gave but I wanted to add the controls to the PlayGui control. I got that working but I want to be able to using a loop change certain properties of the bitmap controls. Here is my code but it doesn't work :( My error is in the bottom function which I am sure you guessed. I am open to any suggestions.

for(%i = 0; %i < 10; %i++)
{
%x = 623 - (17*%i);
%y = 2;
echo("Place heart at " @ %x @ ", " @ %y);
PlayGui.add (new GuiBitmapCtrl("Heart"@%i)
{
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = %x SPC %y;
extent = "15 15";
minExtent = "15 15";
visible = "0";
helpTag = "0";
bitmap = "./HeartDark25.png";
wrap = "0";
});
}

function UpdateHeartHUD()
{
%MaxHealth = 5;
%CurrentHealth = 3;

for(%i = 0; %i < 10; %i++)
{
"Heart"@%i.setVisible(1);
}
}
#9
07/13/2005 (1:21 pm)
@Eric
I believe if you change
"Heart"@%i.setVisible(1);
to
("Heart"@%i).setVisible(1);
it should work.
#10
07/13/2005 (1:35 pm)
Thanks that did the trick. I am still trying to get the script syntax nailed down. Being able to do that in script is very powerful and easy.
#11
07/13/2005 (3:31 pm)
The reason the other syntax doesnt work is because the order of operations. The way you had it, the game would try to call setVisible on %i and then concanenate whatever that returned onto "heart".