Game Development Community

Translating TorqueScript to English

by Ganef · in Artist Corner · 05/10/2012 (1:44 am) · 13 replies

Sorry, ahead of time, if this has been discussed before.

In TorqueScript it says:

function FishClass::onLevelLoaded(%this, %scenegraph)
{
%this.setLinearVelocityX(20);
}


In plain english it means:

The instant in which you load the level, set the linear velocity, on the object called FishClass.

Yes? No? Kinda? Am I getting the picture?

About the author

A nomad, fighting against the apparatus of the state throughout the deserts of the horizon of the infinite.


#1
05/10/2012 (1:49 am)
That would set the linear velocity on the Class called FishClass.. Not the object. Therefore it would hit all the objects with the class FishClass.
But yes i believe that would set it to move with the velocity 20 along the x-axis. Therefore it would move right on the screen.
#2
05/10/2012 (9:47 am)
Thank you.

What I am saying is more of a general observation.


When you translate TorqueScript to English, you see that TorqueScript has some fucked up syntax.
#3
05/10/2012 (10:05 am)
That would be the case with most programming languages. Try this one in Perl:
$_=q{$_=q{Q};s/Q/$_/;print};s/Q/$_/;print
#4
05/10/2012 (12:32 pm)
That Perl one is a wild one. I have no clue what it means.
#5
05/10/2012 (1:09 pm)
It's a Quine, which is fun in and of itself.
#6
05/10/2012 (8:03 pm)
$_=q{$_=q{Q};s/Q/$_/;print};s/Q/$_/;print

Jesus! That reminds me of sarge yelling at Beetle Bailey.


i1.cpcache.com/product/395780596/sarge_yelling_35_button.jpg?height=225&width=225
#7
05/11/2012 (2:24 am)
I think the Torque syntax is really nice and easy to read actually.. But that might just be the result of working with it a bit :)
#8
05/11/2012 (6:40 am)
Torque syntax seems fairly C style average, and also very similar to *.gsc used in CoD.
#9
05/11/2012 (12:05 pm)
I think I really, really like Torquescript...

It's not Torquescript that's confusing, it's the adherence to aping the C++ class structure, which is kind of unavoidable given that it is naked C++ exposed to the console. I really think the expectation was set by the Ancients of Torque that heavy lifting was intended to be written in C++ and the script be used as glue to attach the art assets; i.e., the target audience were assumed to be polymaths.

I've done some actually ridiculous things in Torquescript, and find it light and fast, which is a darn good thing given how weak my C++ is--my Torquescripting has only improved since I read through Bruce Eckels' C++ book (available at www.ibiblio.org/pub/docs/books/eckel/) and spent some time reading the engine classes.
#10
05/15/2012 (10:52 pm)
Another translation question from the Fish Demo.

If TorqueScript says:

function FishClass::onWorldLimit(%this, %mode, %limit)
{

switch$ (%limit)
{

case "left":
%this.setLinearVelocityX(20);
%this.setFlipX(false);

}

}


In Plain English it means:

If the case is "left", the instant you hit the world limit, set the linear velocity to 20. At the same time, the instant you hit the world limit, set the FlipX function to false.

This much I understand. What is confusing me are the symbols above it. Anyone care to explain what does switch$ and (%limit) mean, in plain English? Could you use it in a sentence?
#11
05/16/2012 (5:51 pm)
switch$ is a global variable. If you see a $ sign, it means the code can be reached from anywhere.
%limit is a local variable and can only be reached thru the function itself.
#12
05/16/2012 (6:04 pm)
I would read that as: Once the FishClass object reaches the world limit determine which limit has been reached, and do something depending on which case condition is met.

A switch operation is just a cleaner/simpler version of a bunch of if/else if statements.
switch$ means your case evaluations will be strings (words)
switch means your case evaluations will be values/numbers

%limit is a parameter or argument passed into a function. The % in front of it means it is a local variable, usable only within the scope of this function. A $ in front of a variable would indicate a global variable. Global variables can used anywhere within the code.
#13
05/17/2012 (5:29 pm)
Also note:

If comparing words like "left" or "dog" you need to use $= to mean they are equal ( "dog" $= "dog" ) and !$= to mean they are not ( "dog" !$= "cat" ). For values you use == to mean they are the same ( 1 == 1 ) and != to mean they are not ( 1 != 2 ).

$switch is a global variable named switch, switch$() is a keyword that uses a word to match cases to perform operations (in case Mike's great explanation was unclear to anyone).