Game Development Community

scripting variables

by Ron Yacketta · in Torque Game Engine · 04/12/2002 (3:57 pm) · 6 replies

Hello everyone,

I have been doing some examples to aid in my understanding of the scripting language.

I noticed that variables in most cases are saved between missions. IE: if I load a mission , do something to access some functions that set variables and then exit the mission and start a new one (via esc) the variables are still present.

I was thinking of using deleteVariables(some scope here), but was wondering if their is an easier way to
delete/unset variables between mission loads.

Regards,
Ron

#1
04/12/2002 (4:44 pm)
My personal inclination in scripting is to use as few global variables as is possible.

Instead I make all my variables as an objects variable.

eg.
Instead of going
$PlayerInventoryStuff[%player] = %bla;
I would use

%player.InventoryStuff = %bla;

At the end of the mission all the game objects are deleted and hence, so are the variables. Nice way to clean thigns up.

If you must use global variables you are really stuck with the deletevariables command
#2
04/12/2002 (4:58 pm)
Thanxs!
Learn something new everyday :)
I was unaware that you could create a variable on the fly like that. I know of the usual $variable and %variable, but to use %object.variable just adds to the flexibility of the TGE scripting language.

-Ron
#3
04/12/2002 (5:31 pm)
I seem to be missing something simple here, I created a basic GuiBitmapCtrl object and then attempt to use the variable decleration you mentioned.

in the clientCmdPopTestObject I do

%TestObject.MyVariable = 100;

in a member function of TestObject I do

echo("==> " @ %TestObject.MyVariable);

but all I get in the console is

==>

I am wrong in setting up the variable in the clientCmdTestObject ?

-Ron
#4
04/13/2002 (12:20 am)
What is you %TestObject?
Normally you got something like:
function doMeSomeFavour(%this, %that)
{
   %this.myNewVar = "bla";
   echo(%this.myNewVar);
}
Maybe that's the problem...
#5
04/13/2002 (6:38 am)
I ended up saving the %player to a global variable and then defining my variables from it.

$gPlayerObject = %player;

$gPlayerObject.some_variable = some_value;

I decalre/init $gPlayerObject in the clientCmdPopTestObject{} as well as set the initial variables and their values.

This enables me to access $gPlayerObject.some_variable anywhere in the script (should also be able to access anywhere in any client script)

Regards,
Ron
#6
04/13/2002 (2:45 pm)
Quote:
%TestObject.MyVariable = 100;

in a member function of TestObject I do

echo("==> " @ %TestObject.MyVariable);

but all I get in the console is

==>

I am wrong in setting up the variable in the clientCmdTestObject ?

The reason this did not work is due to scope on local variables. If you would have defined it in the method you used it then it would have worked.

-Tim aka Spock