Game Development Community

I need help to understand torquescript

by Mike Carner · in Technical Issues · 07/02/2007 (3:38 pm) · 2 replies

I'm extremely interested in developing things for TGB, which i am currently using, except i seem unable to understand torquescript and construct scripts that are executed without problems.
I've tried through trial and error to identify how to get a function to execute, but constantly fail at getting it to work. I do have experiencing with programming of some kind, as I have constructed programs on my TI-84 throughout my 4 years in highschool (And i kind of think it may be the reason i'm having problems now because i keep trying to to do things the calculator way) so i understand the psychology of writing script.

Ok, here is my problem. I have an object and I wish to use the moveto() function. This is what i currently have for trying to execute it.

$playerchar.moveTo(%targetX, %targetY, %speed, %autoStop, %callback, %snap, %margin);
{
%targetX = 1.201
%targetY = -30.791
%speed = 20
%autostop = 1
%callback = 0
%snap = 1
%margin = .1
}

playerchar is the object and have it setup to go to a certian point when a button is pressed (this function is within another function linked to it) I've also tried putting the variables in for the arguments in the field inside the parentheses of the moveto() thing an d i could not get it to work. The error reporting in the console doesn't seem specific enough for me to identify what i'm doing wrong. I would just like an example of what i'm supposed to be typing.

About the author

Recent Threads

  • Loops causing crash

  • #1
    07/02/2007 (4:08 pm)
    I think it'll take more than just this function to get an object to move to a location,
    but this specific function should probably look more like this:

    Player::moveTo(%this, %targetX, %targetY, %speed, %autoStop, %callback, %snap, %margin)
    {
       %this.targetX = 1.201;
       %this.targetY = -30.791;
       %this.speed = 20;
       %this.autostop = 1;
       %this.callback = 0;
       %this.snap = 1;
       %this.margin = .1;
    }

    which could then be called like this: $playerchar.moveto(%targetX, etc, etc);
    #2
    07/02/2007 (7:00 pm)
    Heh, I'm pretty sure 'moveTo' is actually an already present function in the SceneObject class ... and your use is a bit goofed ...

    $player.moveTo(1.201, -30.791, 20, 1, 0, 1, 0.1);

    That's how you 'call the function' and pass the variables you want ... you don't reference the variables by name in the function call, and you don't place the function definition first ... I can sort of see where you might have gotten this idea by looking at datablocks and object instantiations ... but, had you actually read the docs or even briefly looked at one of the sample tutorials ... you'd of known right off hand where you went wrong as this subject is clearly covered.