Game Development Community

Local and global script variables ?

by RageO · in Torque Game Engine · 10/22/2006 (1:19 am) · 5 replies

Hey all. I am new to Torque and C++ but not new to programming. I am trying to get my head around the scripting and I am having trouble with a few things.
I found a global list of variables such as "$mvBackwardAction " and I know if I change the value It will move a character backwards etc.. I know how to define my own local variables , about for loops functions etc..

However , I am getting confused on the variables that seem to be for the engine itself(the ones I am NOT defining) such as the %val and %this variables like in the example below.

//---------------------------------------------
function moveleft(%val)
{
$mvLeftAction = %val * $movementSpeed;
}
//----------------------------------------------

I know what happens when this function is called but NOWHERE in the script is %val defined!
Where is the information for this comming from ? Same with %this. Can some one please help me out here or point me to some reference material that will make sense of this ?


There are other variables / commands (forgive me if I am using the improper term) such as the command

"rotation" used like rotation = true ;

Where can I find a list of these commands so I know what I am working with ? I have the global listing its the local ones and the commands like rotation , and static that I am looking for a list of.

Thanks
Confused scripter

#1
10/22/2006 (2:22 am)
%val is local so it is defined right there. You could rename it to %pancakes for all you care, and it will still work. You could say that it is defined in the function header. It is not used outside that function.

$mvLeftAction is not defined anywhere special either, it just happens to be used and accessed by the engine internals. I know that one might be confusing.
#2
10/22/2006 (2:58 am)
Thanks.
That helps confirm a bit of what Ive found through searching. I also found the list of field references finally so the filds like rotate static mass etc... make sense now.

I thought fields were variables(they are in a sense) and I could not find where they were being used. But I realize now the engine is using these and there is no need for me to create the code to actually use these because its done for me.

Still a bit confused but I found some great resources finally after alot of digging around. I was looking for the script references which are a bit hard to come by. But finding them made things as far as the scripting make a whole lot more sense.
#3
10/22/2006 (3:57 am)
Glad to hear. Make sure to ask if you got any more questions :)
#4
10/23/2006 (12:25 am)
Ok Im slowly seeing the light. I just want a little confirmation here to make sure Im thinking right.

Just let me know If I am thinking correctly on these things here and feel free to elaborate on anything I may be missing or have incorrect.

1.When we use a datablock we use a class to define what kind of data block we are definning and that is followed by a list of fields and parameters associated with that particular data block ?

2. I was confused on where the functions for my Items were being called such as when I made one that would rotate a cube. In the example below the mission editor is actually invoking this function when I put the Item in the worls. This is stored in the .mis file and called when the level is loaded.

function ItemData::create(%data)
{

%obj = new Item() {
dataBlock = %data;
static = true;
rotate = true;
};
return %obj;
}

Things are slowly making sense I think. I under stand the functions but for the life of me I could not see where they were being called. I was under the impression that I had to call them my self somewhere and going nuts trying to figure it out. But if it is written right then the mission editor does it on Item creation. Most of the comments are right there but it has not made a lick of sense till now.
Is this essentially correct ? Please feel free to add anything that I am missing or that would be helpfull to know. Im just trying to get the stucture figured out so I can get to scripting some cool objects :)
#5
10/24/2006 (1:29 pm)
I'd make a seperate file for your object, like myObject.cs and then exec that in your game.cs file in the onServerCreated() function.

example:
myObject.cs
datablock ItemData( myObject )
{
... parameters...
}

then create it someplace in your code ...

%theObject = new ItemData()
{
datablock = "myObject";
};

and in onServerCreated()
exec ("myObject.cs"); // make sure the path is right if its in a different directory