Game Development Community

Compiling Scripts

by Vern Jensen · in Torque Game Builder · 06/17/2006 (3:09 pm) · 3 replies

Perhaps I'm not doing it the right way, but it seems to me that the process for writing scripts and testing them is:

1) Edit the text file.
2) Quit and restart TGE so the scripts re-compile.
3) Run

The problem is that at step 2, I don't get any compile errors if there are problems in my script. And I mean problems that should be obvious to any normal language compiler, such as:

function playerShip::updateMovement(%this)
{
%hDirection = this.moveRight - %this.moveLeft; // OOPS! Forgot % on this.moveRight

or

%this.setPositionX( %this.getWorldLimit().maxX ); // WRONG!

(correct code would be this instead)

%theList = %this.getWorldLimit();
%this.setPositionX( getWord(%theList, 3) );

I get no warnings or anything. The game just runs. It doesn't work right, but I get no indication which lines in my script might be at fault.

My suggestion: Add a Compile or Build or Make button next to the Run Game button in TGE. This compiles all your scripts (no need to quit and restart TGE), AND reports any syntax/other compile errors. This would be SO helpful.

-Vern

#1
06/17/2006 (5:20 pm)
1. In RC3 its supposed to recompile your scripts when you run the level . It seems to work for me, are you at RC3?

2. this is a valid name, I dont think it should try and trap things like that , you could have a class name called "this", thats why you run unit level tests and QA.
#2
06/17/2006 (11:00 pm)
Those are not syntax errors. They are valid TorqueScript.

On this.moveRight ...

You can access objects by name. For example:

new ScriptObject(this)
{
   foo = "bar";
};

That'll make a new ScriptObject called "this" with the field foo set to the string bar. You can then access that object anywhere else in your scripts as this ... e.g.:

echo("How confusing: " @ this.bar);

Yes, it's confusing. No, it's not a syntax error. Note that a lot of existing code relies on this feature (although using more sensible names then "this"), there is no way for the compiler to know if you actually meant to use %, $ or an object name.

On %this.setPositionX( %this.getWorldLimit().maxX ); ...

You'll get an error in the console about an invalid object at run time because at compile time the compiler doesnt know what %this.getWorldLimit() returns.

So, in summary, these errors are just due to you misunderstanding/not knowing the language and API. The compiler can't tell you that they are errors because it simply doesnt know and there is no way for it to know.
#3
06/19/2006 (12:07 pm)
Alright, thanks for the replies.

Rodney, to answer your question, yes I'm using RC3, but I'm on MacOS X. Perhaps the MacOS X RC3 version still has this problem, because I definitely have to quit and restart TGE to get the scripts to recompile. It's not a big deal -- it quits and restarts in about a second or two.

-Vern