Arrays?
by Thomas Pereira · in Torque Game Builder · 01/18/2007 (10:38 am) · 2 replies
This is a question I'm more curious about then actually need. There seems to be wonderful support for string arrays. Seems like there is more support for string aways than for normal arrays, hence the root of my question.
With just the standard array (like grid[n] or whatever), what functions are there to help out? I haven't really seen anything in any of the reference docs on regular arrays. What I've been doing for things like arraylen is every time I enter new data into an array, add one to the normal variable...say grid[n] = x, grid++. Basically, all I'm wondering are what functions are there to support arrays, how do I predefine arrays (I've tried all sorts of different ways to pre-define some arrays, like grid = {a,b,c,d}, grid = [a,b,c,d], grid = a,b,c,d, etc, nothing seems to work), or any other info associated with arrays because there seems to be no info about it.
Thanks
-Tom
With just the standard array (like grid[n] or whatever), what functions are there to help out? I haven't really seen anything in any of the reference docs on regular arrays. What I've been doing for things like arraylen is every time I enter new data into an array, add one to the normal variable...say grid[n] = x, grid++. Basically, all I'm wondering are what functions are there to support arrays, how do I predefine arrays (I've tried all sorts of different ways to pre-define some arrays, like grid = {a,b,c,d}, grid = [a,b,c,d], grid = a,b,c,d, etc, nothing seems to work), or any other info associated with arrays because there seems to be no info about it.
Thanks
-Tom
About the author
#2
01/18/2007 (6:16 pm)
Eh, thats unfortunate. I was mainly wondering if there was more support for arrays because I've been mainly using string arrays, or lists, or whatever it's called here - but if there was more support for arrays I figured it would be faster when dealing with numbers. I appreciate the idea presented, but it seems to me string arrays would just be easier to use if there is no built in array support.
Torque 3D Owner Matthew Langley
Torque
it basically does
In fact you can echo back "$grid0" and get 10.
Now if you want to add some basic array functionality, you can using ScriptObjects...
new ScriptObject(ArrayClass) { count = 0; }; function ArrayClass::pushValue(%this, %value) { %this.data[%this.count] = %value; %this.count++; }and then if you want to create an array:
$enemyArray = new ScriptObject() { class = ArrayClass; }; $enemyArray.pushValue("blah");In this sense you can create your own array object with all the functionality you want in the way you want (based around this type of setup).