Game Development Community

No More Coordinates in Ordered Pairs?

by Jeremy Tilton · in Torque Game Builder · 03/11/2005 (11:01 pm) · 5 replies

So most functions in all code I've seen take X,Y coordinates as a string:

$player.setPosition("0 35");

But none of the functions let me say the same thing as an ordered pair:

$player.setPosition(0,35);

Seeing as how the coordinates are described as a string seperated by a space, how do we do math on these numbers? How do I do something like set the player's X coordinate = to its currentvalue + 10?

#1
03/11/2005 (11:16 pm)
%currentPosition = $player.getPosition();
%currentPosition.x = getWord(%currentPosition, 0);
%currentPosition.y = getWord(%currentPosition, 1);

$player.setPosition((%currentPosition.x + 10) SPC %currentPosition.y);
(Edited to properly group the x coordinate math, see below)

TGEScript is a typeless language, so variables can be treated differently in different statements, and the byte code compiler will recognize how to use the variable at a particular point.

In addition, in TGEScript, all parameters to console functions (the interface between script and C++ code) are sent as strings. In this particular case, Melv/Josh decided to pass x,y position coordinates as a single string--they could have chosen to pass them as two separate strings, giving you something similar to $player.setPosition("0", "35");

NOTE: This is TGEScript info, and while I'm pretty confident Melv/Josh didn't change anything in this type of scenario, I haven't actually checked the above directly against T2D source code. Your milage may vary!
#2
03/11/2005 (11:51 pm)
Had to modify very slightly was getting "too many parameters" error:

%currentPosition = $player.getPosition();
%currentPositionX = getWord(%currentPosition, 0);
%currentPositionY = getWord(%currentPosition, 1);

$player.setPosition((%currentPositionX + 10) SPC %currentPositionY);


But that did it, thanks a bunch! Oh, I had a question before about this, think I figured it out, but wanted to double check(off-topic):

are the symbols before the variable names for scoping?
$=global variable
%=local variable
#3
03/12/2005 (2:48 am)
Your variable scoping is correct.

Also, if you check the very last page in the reference doco, I added a bunch of vector utility helpers and more on the way. These should help quite a bit. :)

Good Luck,

- Melv.
#4
03/12/2005 (7:00 am)
Melv, you are superman. How can you be everywhere at once and still develop like a madman? Be honest, you are really 100 people aren't you?

I gotta say, I have a lot of respect for you. You work, have a kid, made a sweet engine, and provide answers in about 90% of the forum threads in this community.
#5
03/13/2005 (2:34 am)
Lots of coffee, headaches and a very understanding and kind wife.

Sounds sickly but it's definately worth it just seeing the 'buzz' on the forums. :)

- Melv.