Game Development Community

Array of ScriptObjects possible?

by Tim Saunders · in Torque Game Builder · 02/06/2006 (6:36 am) · 6 replies

I'm making a simple invaders type game where there is a grid of coordinates which form the potential starting points for each of the invaders. Each coordinate is defines what type of invader is there and other information such as if they've got a shield or hold some sort power up token. So say it is set up like this:

$CoordSpace = new ScriptObject(CoordSpace)
{
InvaderType = 1;
InvaderShield = 0;
PowerUpToken = 0;
}

Then in another ScriptObject that defines the level I want to hold an array of the CoordSpace ScriptObjects:

$Level1 = new ScriptObject(Level1)
{
class = "level";
NumCols = 6;
NumRows = 6;

// Need arrays of invader 'spaces' below

};

Is this possible? Is there a better way of doing this?
I've been through all the tutorials and the ETGTE stuff but can't seem to find the answer. Any help would be greatly appreciated.

#1
02/06/2006 (7:29 am)
Not sure if this will work but i'd try putting them into a simset.
#2
02/06/2006 (7:48 am)
Arrays in torque are strange; use SimSet's instead, because they have more array like things like a .getcount() function (which you'll need).

myarray = new SimSet();
myarray.add(%invaderobj)

etc..
#3
02/06/2006 (9:33 am)
Thanks for the swift response, I've got it working now thanks.

Is there a way of storing data and loading it into a function easily?
Something like this:

Data("1 4 3 2 3 5 6");

for(%a=0;a {
ReadData(a);
Use(a);
}

Or is there a better way perhaps by using the tile editor to do this?
#4
02/06/2006 (12:24 pm)
%data = new simset();

%data.add "1";
%data.add "4";

for (%i=0; %i {
Use(%data.getobject(%i));
}


but if your looking for a way to store a bunch of data and load and save it, I believe there's an automatic way to do this in torque script through external file read/writes; which would be preferable to a data type statement (though I haven't messed with it myself yet).

look up load/save in the docs..
#5
02/06/2006 (1:23 pm)
Here is an old post of mine about saving and loading, scroll down a bit :)
#6
02/06/2006 (3:03 pm)
Hey thanks for the replies, both are very useful indeed. If it wasn't for these forums I would have been totally stuck. I don't suppose that there is any way of loading data from a text file? It would be useful to be able to type in patterns like this:

000 102 110 310 223 241 000 221

To define the invaderswith three parameters for each coordinate space.

EDIT: Actually I've just found out that there is a level builder in the latest release so I'm going to try that out instead.