Game Development Community

getWord(%var, 0) or %var.X ?

by Samuel Cartwright · in Torque Game Builder · 04/29/2009 (5:49 pm) · 3 replies

I've been trying to get my head around torqueScript to program my game.
I've read that to get the x/y values for a position variable I should be using the following:
%x = getWord(%var, 0);
%y = getWord(%var, 1);

Although on some forum posts I notice people using this:
%x = %var.X;
%y = %var.Y;

I'm just wondering if the second method has any side-effects, or if it should only be used in certain cases. Has this been added to torqueScript recently, since I haven't come across it in any tutorials - only forum posts?

Thanks,
Sam

#1
04/29/2009 (6:45 pm)
I prefer to use .X/Y/Z because you can edit the value like this:

%myVar = "0 0";
%myVar.X += 10;
%myVar.Y -= 20;

// "10 -20"
echo (%myVar);

There are a few little issues, you must initialise the variable before use, i.e:

// Doesn't work.
// Must have references %myVar2 above this.
%myVar2.X = 10;
%myVar2.Y = -20;
#2
05/01/2009 (11:40 am)
I agree with Phillip. This way it is easy to edit the variables.
#3
05/01/2009 (11:48 am)
I also believe it improves on memory usage (not much, but still...)