Game Development Community

New to torque script, need few questions answered.

by Law Rus · in Technical Issues · 01/07/2008 (1:39 pm) · 2 replies

I have been working on a game for a month or so on GameStudio, but decided to switch to this for the better particle effects. I'm familiar with C script but a few things are throwing me off with this new language.

Following some tutorials I've managed to create a basic game, but I'm still unsure of how it all works.

For example:

function playerShip::onLevelLoaded(%this, %scenegraph)
{
%this.setTimerOn(25);
}


function playerShip::onTimer(%this)
{
}

the first part of the function, according to a tutorial I read, is the class; which defines what can use the function, but isn't it also the name of the function?

I am using pre 1.3 version of GameBuilder. I heard somewhere that the code is different, but I can't find any articles on this to explain what has changed. So how different is the code?

I see a lot of things which I assume are variables, but I don't see them defined anywhere in the code. I know about the dynamic fields and everything, but what about things like

%targetRotation = mRadToDeg(mAtan(%vector.y, %vector.x)) + %this.rotationOffset;

I found this in a code example for facing the mouse. I don't understand what %targetRotation is. I didn't see it being defined and this is the first instance of it in the code.

Finally, what is a behavior? I was trying to follow a tutorial and it had a behaviors menu in TGB. Is this something new to TGB that I don't have with my old version?

Thank you all.

#1
01/07/2008 (1:53 pm)
TGB uses objects to script, so if an object has the class "playerShip" it may use any function defined as a playerShip class method. If you have an object that would like to access a function in another class you can always use:

OtherClass::functionName(arg1, arg2);

The coding style hasn't changed too much since 1.3, but there are massive upgrades in newer versions, like behaviors for instance. Also, I do not think the %vector.x and %vector.y usages will work in 1.3, I always thought it was a newer implementation. X and Y just refer to the 1st and 2nd words in a string, which can be worked around using:

%VectorX = getWord(%vector, 0);
%VectorY = getWord(%vector, 1);
%targetRotation = mRadToDeg(mAtan(%VectorY, %VectorX)) + %this.rotationOffset;'

Normal variables are not defined, nor are dynamic variables.

%localVariable
$globalVariable
%object.dynamicVariable
#2
01/07/2008 (3:20 pm)
Thank you. That clears things up so much :D