Game Development Community

How to create new script accessible variables? (in code)

by Jacob · in Torque Game Engine · 03/30/2005 (6:26 pm) · 3 replies

I would like to make a GUI Control similar to GuiHealthBarHud which will change when my variable does - like the HealthBarHud....except I need to have a script accessible variable that I can change at any time during the game and have my BarHud be updated. I looked through GuiHealthBarHud.cc and I see that it is hard coded to display energy/damage. For my project, I need a variable that does not belong to any datablock - something like the $pref:: globals. I looked at the "Adding Variables to Datablocks via source code" resource but it doesn't seem like it's what I need. Thank you for any help.

#1
03/30/2005 (8:30 pm)
MGuiScriptVariable = dAtof(Con::getVariable("pref::globals"));


Depending on what variable you are using and what the GUI needs you may not need the float conversion. You may need another type or none at all. Try the following first to see i it works for you...


mGuiScriptVariable = Con::getVariable("pref::globals");


The only other thing is to make sure the GUI is exposed to teh console via...

#include "console/consoleTypes.h"
#2
03/30/2005 (8:41 pm)
Look in my profile and click on the resources i've submitted buttoin and you will find a resource I did a while back for TGE that is a complete tutorial on adding new scriptable objects in C++ code. That should have all the info you need.
#3
03/31/2005 (4:58 pm)
@Gonzo - thanks for your help again, it was exactly what I needed and I have my new GuiHud in place.

@John - thans for the info - I have looked through it and it looks like it may come in handy at some point.