Author Topic: embedded arrays  (Read 2000 times)

Quick question.
Does anyone have experience getting embedded arrays to work?
I can't find a good example of them in published mods which is disconcerting as they seem to be the easiest way for me to do all the type checks I'm doing without spamming datablocks.

Any tips?

Use script groups and script objects. This should work as long as you are organized to prevent memory leaks.

Edit: Here's an example, it is untested but you should get the idea:

new scriptGroup(cars);

new scriptObject(bmw)
{
   Name = "BMW";
   Speed = 120;
   Doors = 4;
};

new scriptObject(Honda)
{
   Name = "HONDA";
   Speed = 100;
   Doors = 2;
};

cars.add(bmw);
cars.add(Honda);

echo(cars.getObject(0).name);
« Last Edit: April 01, 2014, 10:46:32 PM by elm »

What exactly do you mean "embedded" arrays?

I almost didn't recognize you without your crab avatar. Wtf, how could you change that?



I'm not sure what you mean by an embedded array. What is it embedded in? An object?

Code: [Select]
%obj = new scriptObject();
%obj.array[0] = 0;
%obj.array[1] = 1;
%obj.array[2] = 2;

That 'embeds' an array into an object. Or did you mean what elm said with a script group?

Use script groups and script objects. This should work as long as you are organized to prevent memory leaks.

cool that looks like what Iwas looking for thanks

related question to answer
is there an easy way to delete an unused script object and its componants?


For its constituents you'll have to loop through and delete them (and, possibly, their own constituents) manually.

Code: [Select]
package mySODelete {
    function mySO::delete(%this) {
        for(%i = 0; isObject(%this.subObject[%i]); %i++)
            %this.subObject[%i].delete();
        parent::delete(%this);
    }
};
activatePackage(mySODelete);

For ScriptGroups, just call ScriptGroup::deleteAll() and ScriptGroup::delete().

So it's not possible to create two-dimensional arrays in Torquescript?

So it's not possible to create two-dimensional arrays in Torquescript?

Yes it is.

$blah[1,2] = "apples";

So it's not possible to create two-dimensional arrays in Torquescript?

"two dimensional arrays"

bold on the quotes

So it's not possible to create two-dimensional arrays in Torquescript?

http://tsforblockland.weebly.com/arrays.html

Scroll all the way down.

$What["the", "forget", "am", "I"] = "doing?";

You can make arrays of any dimension you'd like :iceCream:

Keep in mind when using that: Having an underscore in the values can cause unexpected behavior.

Keep in mind when using that: Having an underscore in the values can cause unexpected behavior.
i can imagine the catastrophe already oh god