Global Variables
by Jonny · in Technical Issues · 07/08/2006 (6:43 pm) · 4 replies
Hi, Im still getting to grips with c++ in Torque and Ive come into a problem. I need to write global variables for a boat transport script Im making. Basically, Ive spawned a boat which is fine, but then after 10 seconds I want to set its velocity so it moves. The only way I know how is to schedule another function. This means the local variables will be removed from the scope so they cannot be used. Because of this, I need a Global Variable, but I dont know how to set one in Torque? I need to set a Global variable for a certain type of datablock in the code. I would be very grateful if someone could help since this would solve some other global variable problems that I have aswell!
Thanks, Jon.
Thanks, Jon.
About the author
#2
$myVar = "blah blah"; creates a global variable.
%myVar = "blah blah"; creates a local variable.
Check out the GettingStarted.pdf file in your /Torque/Example/ directory, or the TGE docs for more info.
Have fun!
-- JohnDopp
07/08/2006 (11:54 pm)
Ramen's right, you can just pass the variables. But, if you really want to make them global:$myVar = "blah blah"; creates a global variable.
%myVar = "blah blah"; creates a local variable.
Check out the GettingStarted.pdf file in your /Torque/Example/ directory, or the TGE docs for more info.
Have fun!
-- JohnDopp
#3
If you need a global variable in C++, the easiest way to do this would be to pick a class that it seems most to belong to (not an object instance, but a class... like, say, a mouse class for whether or not it is in mouselook - just to make something up) and then create a static variable on this class. Then, you can reference this static variable anywhere in your application just by referencing it through the class (my C++ is rusty, but in Java or C#, it would be ClassName.Variable instead of instanceName.Variable).
07/09/2006 (12:00 am)
Though technically, guys, if he's talking C++ and not TorqueScript (which I am not thinking he is, but IF he is) then the suggestions about TorqueScript won't help.If you need a global variable in C++, the easiest way to do this would be to pick a class that it seems most to belong to (not an object instance, but a class... like, say, a mouse class for whether or not it is in mouselook - just to make something up) and then create a static variable on this class. Then, you can reference this static variable anywhere in your application just by referencing it through the class (my C++ is rusty, but in Java or C#, it would be ClassName.Variable instead of instanceName.Variable).
#4
07/09/2006 (1:18 am)
Doh! You're right, Cliff... it's late, and I'm only reading every other word. Mea culpa. =)
Torque Owner Cinder Games