Game Development Community

Var.x, %var.y, %var.z

by Phillip O'Shea · in Torque Game Builder · 05/08/2008 (5:34 pm) · 3 replies

I am sure there are people out there that do not realise that these little helpers exist, but I appear to be having a problem with them in TGB 1.7.3. It is possible that they occur in other versions, but I am unable to reproduce this bug in a frequent setting.

There are two main problems.

1. You must have N number of words in the variable before ever using the .x .y .z suffixes. For example:

// Works perfectly
%myVar = 1 SPC 2 SPC 3;
echo ("MyVariable: " @ %myVar);
echo ("MyVariable X: " @ %myVar.x);
echo ("MyVariable Y: " @ %myVar.y);
echo ("MyVariable Z: " @ %myVar.z);

// Also works perfectly
%myVar.x = 3;
%myVar.y = 2;
%myVar.z = 1;
echo ("MyVariable: " @ %myVar);
echo ("MyVariable X: " @ %myVar.x);
echo ("MyVariable Y: " @ %myVar.y);
echo ("MyVariable Z: " @ %myVar.z);

// Does not work perfectly
%testVar.x = 1;
%testVar.y = 2;
%testVar.z = 3;
echo ("TestVariable: " @ %testVar);
echo ("TestVariable X: " @ %testVar.x);
echo ("TestVariable Y: " @ %testVar.y);
echo ("TestVariable Z: " @ %testVar.z);

2. This one I can't repeat all the time, but it might be something to do with passing it through functions? Anyway, sometimes you can echo X Y Z from a variable and it will not be the same as the values inside the whole variable. For example, you could echo %myVar.X and %myVar.Y and it will contain "1" and "2" and then echo %myVar and it could be "80 15".

The first one is easy to reproduce, but the second one only happens sometimes.

I am sure it isn't the correct place to ask, but can we please get this functionality in other Torque engines (TGE and TGEA)?

About the author

Head of Violent Tulip, a small independent software development company working in Wollongong, Australia. Go to http://www.violent-tulip.com/ to see our latest offerings.


#1
05/09/2008 (12:22 pm)
I was unaware that .X/.Y/.Z existed...

So doing this:

%var.Y = "15";

Is the equivalent of:

%var = setWord(%var,1,"15");

Actually it would need to be more complex and perform a strcat if the LPARAM has a wordCount less than the one being accessed.
#2
07/28/2008 (8:45 am)
I always thought that this was intended behaviour, that the outer variables needed to be initialized before any inner variables could be ie.
function myFunction()
{
   %testVar = new SimObject();
   %testVar.x = 10;
   echo(%testVar);
   echo(%testVar.x);
}
works perfectly. However, seeing this example has convinced me that this is indeed a bug since removing the first line of the function causes the program to crash when the code is run.
#3
07/28/2008 (12:49 pm)
BlueRaja, in my case, the variable in question most definitely is not an object, it is a string. In your case, you reference a dynamic field of an object.

%testVar.X/.Y.Z is the equivalent of getWord(%testVar, 0/1/2) or setWord(%testVar, 0/1/2, "newValue").