Game Development Community

How to create pointer to an array ?

by Arsen Gnatkivskyi · in Torque Game Builder · 05/13/2007 (5:36 pm) · 4 replies

Hi all !

I need to appropriate pointer to an array like this

%foo[1,4]=222;
%boo=%foo;
%result=%boo[1,4]; // must be 222

How to do it correctly ?

thanks

#1
05/14/2007 (12:43 am)
Arrays are not really arrays in torquescript but a load of variables with index attached to it, so the only way I can think of having an array widely spread across the code (that's why you probably want it I guess) is to have all the array (meaning all the variables that look it) as globals.

So you would need to have $foo instead of %foo or a script object known everywhere by name or class and then the array inside.

I know that this "array is not an array in ts" is a bit weird for starters, but check your docs on how to work with arrays and you'll understand what I mean. Treat each array data as a separate variable and you'll be fine.

Hope this helps.
#2
05/14/2007 (9:05 am)
In Torquescript arrays can't really have pointers. However, depending on what you're trying to do you can probably achieve it by creating the array inside a scriptobject:
%foo = new ScriptObject(){};
%foo.array[1,4] = 222;
%boo = %foo;
%result = %boo.array[1,4];
#3
05/14/2007 (9:31 am)
Dan's suggestion is good. don't forget to %foo.delete() at some point.
#4
05/18/2007 (7:05 am)
Thanks a lot ! It solved my problem !