Game Development Community

Is the a pointer to an object in TorqueScript?

by Andy Hawkins · in Technical Issues · 09/02/2006 (6:39 pm) · 1 replies

I have a bunch of objects like this...

$MyObject[10]

However I also have a bunch of objects like this...

$MyOtherObject[10]

I would like to retain this separation but sometimes I would like to access this data in a more generalised form.

I want to do something like this....

switch(type)
{
    case 1:
                 %obj = $MyOtherObject;   // notice no array 
    case 2:
                 %obj = $MyObject;            // no array again
}

then I want to do this...

for (%i = 0;  %i <  10;  %i ++)
{
         // do something
         %obj[%i] += 1;                        // notice I am using the array this time 
                                                          //- but this isn't legal right?
}

Torque doesn't like this because I would have to set %obj to an explicit memory address right, like %obj = MyObject$[value]? Or is there a way do it with out explicitely stating the array element when %obj is defined / assigned?

#1
09/03/2006 (12:44 pm)
Arrays, like most things in TS, are faked. When you say $MyObject[10], you are not creating an array, you're just defining a variable called $MyObject[10]. The parser has a hack that lets you say $MyObject[%i] to reference such a variable as if it were part of an array. It's possible you can get away with assigning "$MyObject" and "$MyOtherObject" to %obj as strings, but that would only work for sure with eval.

Really you should probably just be using Simsets.