Blockland Forums > Modification Help
Scriptobjects
HellsHero:
Alright, I understand how scriptobjects work and all, but there's one problem I encountered that I can't solve.
I'll try to explain it best I can:
In the Scriptobject, I have the variables Type[0], Type[1], ... Type[x] and I want to be able to remove Type[2] and have all the other types 'move down'. So Type[3] becomes Type[2], Type[4] becomes Type[3] and so on.
How would I make it so they will 'move down'?
Iban:
You want to use a ScriptGroup/ScriptObject coupling.
ScriptGroups are essentially SimGroups with the ability to be extended upon, like ScriptObjects.
For instance:
--- Code: ---function MommaBear::addBaby(%so)
{
%baby = new ScriptObject()
{
class = "Bear";
maternal = %so.getID();
name = getRandomString(5) SPC getRandomString(10);
};
if(isObject(%baby))
%so.add(%baby);
else
error("::addBaby() - ScriptObject not created!");
}
if(!isObject(MommaBear))
{
new ScriptGroup(MommaBear)
{
class = "Bear";
name = "Momma";
};
for(%a = 0; %a < getRandom(3, 8); %a++)
MommaBear.addBear();
MommaBear.listObjects();
}
--- End code ---
Truce:
--- Quote from: Iban on March 14, 2011, 01:35:13 PM ---You want to use a ScriptGroup/ScriptObject coupling.
ScriptGroups are essentially SimGroups with the ability to be extended upon, like ScriptObjects.
--- End quote ---
These can be very risky if you need to preserve order. Removing objects will sometimes shuffle the list.
As for moving things down, you can do a loop through each and set it to what will be moving into it.
--- Code: ---for(%i = %slot; %i < %count; %i++)
%object[%i] = %object[%i + 1];
--- End code ---
Iban:
--- Quote from: Truce on March 14, 2011, 01:38:57 PM ---These can be very risky if you need to preserve order. Removing objects will sometimes shuffle the list.
--- End quote ---
I have never seen a ScriptGroup/SimSet/SimGroup ever shuffle the list of objects. Provide an example on how to produce this.
Edit: You're right, but it doesn't shuffle, it just sticks the last object in the list in the place that the recently deleted object was in.
HellsHero:
Thanks for the quick replies, I really had no idea of what I should have been doing.