Learning Torquescript
by Raymond Clark · in Torque Game Builder · 06/29/2010 (2:13 pm) · 1 replies
Hi all, I am a little new to TGB. I am familiar with C++. Torquescript seems much like it, but theres alot that I am not seeing. I have went through the tutorials and learned alot. Is there any class declarations, prototypes and things like it in Torquescript. An example of something I am not getting is...
function baseClass::onLevelLoaded(%this, %scenegraph)
{
$thebase = %this;
%this.setDamping(4.8);
//............
$thebase.myTrail.isplaying=true;
%this.setTimerOn(250);
}
This is an excerpt from the breakout tutorial. Is onlevelLoaded a function of Torque, or is it a user defined function? also :onLevelLoaded(%this, %scenegraph). Is this a function, defining a class or an object? Also, $thebase.myTrail = %trail; using the .myTrail , is this defining something , even though its not anywhere else? Hope I am not confusing anyone.
function baseClass::onLevelLoaded(%this, %scenegraph)
{
$thebase = %this;
%this.setDamping(4.8);
//............
$thebase.myTrail.isplaying=true;
%this.setTimerOn(250);
}
This is an excerpt from the breakout tutorial. Is onlevelLoaded a function of Torque, or is it a user defined function? also :onLevelLoaded(%this, %scenegraph). Is this a function, defining a class or an object? Also, $thebase.myTrail = %trail; using the .myTrail , is this defining something , even though its not anywhere else? Hope I am not confusing anyone.
Torque Owner Kevin James
Other callbacks you have to enable for the class such as onUpdate, onCollision and mouse events:
I put these commands in the onAdd() callback of my classes since I create them dynamically rather than in the level editor. But if you do create an object in the editor and you want to set it up before anything else happens, then use onLevelLoaded.
You will also have to make your own class methods. For example, here's a custom ("user defined") method in my player class:
function player::shipCount(%this,%type) { %cnt=0; for (%n=0;%n<%this.fleet.getCount();%n++){ %ship=%this.fleet.getObject(%n); if (%ship.ship$=%type) %cnt++; } return %cnt; }Obviously, I call this when I want to know how many ships of a certain type are in my player's fleet.
Another thing about parameters in Torquescript: you can make up variables as you go along. You rarely declare anything is TS. That can get you in a lot of trouble so be careful. You make stuff up as you go along and never see an error message because TS lets you do anything you want without enforcing declaration. "enforcing" is the wrong word because you can't declare variables if you wanted to. Its funny when I go back to my professional IDE after working in TS for awhile and get inundated with error messages because I'm TS stupefied.