Game Development Community

Mapping variables to GuiControl elements...

by Jeffrey Bakker · in Torque Game Engine · 10/12/2005 (6:47 pm) · 3 replies

I was looking for a good, efficient way to display variables in not only HUDs but in dialogs and menu screens as well. I came accross this tutorial, which is neat, but any time the variable changes you need to call a function to redraw the text. This would be a problem for me, if I want to display many variables, most of which may be affected by many different things, both directly and indirectly (and possibly in both C++ and TorqueScript driven events).

Or maybe it would it be easier just to write my own GuiControl in C++, kind of like the guiHealthBarHud (but with text). I'm wondering how often onRender() gets called. If it's called constantly, I would definately consider doing this.

Are there other options that anyone can suggest? Thanks.

#1
10/12/2005 (8:46 pm)
You can tie variables directly to Gui's by using the "variable" field in the Gui itself. It will automatically update based on the value of the (script) variable.

If you need it to reference engine based variables, expose that variable as a persistent field.
#2
10/12/2005 (9:06 pm)
It's that easy, eh? LOL

I'm beginning to like Torque a little more everytime I learn something (and I was very impressed to begin with).

Edit:
One more question about this topic - how would I address an exposed variable from a PlayerData based class in the GUI itself? eg. $PlayerBody.VarName or something...

Thank you very much for the help.
#3
10/12/2005 (9:47 pm)
If it's exposed as a persistent field, (which means it has a script handle directly to the memory location), just use that variable name.

If it isn't exposed, but you have an objectID of the object that has the member variable you want to display, you can play with the onRender and an accessor console method to display the information as well. In that particular case, the resource mentioned above is one way of doing it.