Game Development Community

Making a Struct array that corresponds to an array of objects

by Daniel Novatnak · in Torque Game Builder · 01/15/2008 (9:13 am) · 10 replies

Using Torque Game Builder v1.5

What I am trying to do is creating an array of Objects with name pie(0)...pie(n) where n is an integer

I can't do that with any success; I tried manually with 5 objects, kept getting errors that I couldn't decipher.


Next I want to create an array of nodes(or structs) that each contain pie
So in C it would be:

struct aPie{
object ObjectPie;
int state=0;
int inUse = 0;
};

then to create it it would be

struct aPie Pies[n];
for(int i=0; i Pies[i].ObjectPie= pie(i);

How do I do convert this C to Torque Code and create that in game array of objects?

#1
01/15/2008 (9:28 am)
Try something like:
for (%i=0; %i<10; %i++)
{
    %pies[%i] = new ScriptObject() {
        state = 0;
        inUse = 0;
    };
}
#2
01/15/2008 (10:40 am)
Pardon my ignorance, but what is "ScriptObject()" and what does it exactly do?

I think it creates a datablock and stores that data in it, but I am not positive.
#3
01/15/2008 (10:45 am)
A ScriptObject is an object that is frequently used when writing scripts. What does it do? It holds fields, and it can have a class. It doesn't create a datablock (datablocks are different kinds of objects). I don't know if that explains it clearly.
#4
01/15/2008 (12:25 pm)
Alternatively:

%pies = new SimSet();

for (%i = 0; %i < 10; %i++)
{
    %newPie = new ScriptObject() {
        state = 0;
        inUse = 0;
    };
    
    $pies.add(%newPie);
}

SimSets store lists of objects and can be manipulated much more easily than TS arrays.
#5
01/15/2008 (4:32 pm)
If I used SimSet how do I access an element? The same goes with ScriptObject.

For the ScriptObject wouldn't I need to declare the size of array in advance?

But one thing that I need answered is: How do I make an array of objects of t2dStaticSprite so I can access them like I would the "pies " array?
#6
01/15/2008 (4:40 pm)
You access the elements of a SimSet with the .getObject(index) method. I don't understand the second part of your question. Do you mean access the fields of the ScriptObject?

Torquescript doesn't do pre-declaration. You create an array by assigning things into an array variable.

You can create an array (or SimSet) of static sprites the same way that you can create ScriptObjects.
#7
01/15/2008 (5:36 pm)
In my Code I write

Quote:
%n=10;
for (%i = 0; %i < %n; %i++)
{
$pieObj[%i] = new t2dStaticSprite(){
scenegraph = t2dscene;
};
$pieObj[%i].setImageMap(pie_ImageLink);
$pieObj[%i].layer = 8;
}

....
now in another .cs file

$pieObj[0].mount($player, 0, 0, 0, true);



However, it doesn't mount anything to $player. Any insight into why nothing is being mounted?
Console reports "unable to find object: ' ' Attempting to call function mount"
#8
01/15/2008 (5:42 pm)
Is the scenegraph that $player is in named "t2dscene"?

Is pie_ImageLink the right name for your imageMap?

Try setting the size of the sprite.
#9
01/15/2008 (6:10 pm)
It was the scenegraph that was causing the error. Thanks for the help, just 1 last question, what is a scenegraph and how do I give it a name?
#10
01/15/2008 (6:41 pm)
A scenegraph is a data structure that contains the objects that get rendered to the screen, so basically your scene or level. In TGB, if you go to the Edit pane with no objects selected, you can name your scenegraph in the Scene Graph Scripting rollout.