Author Topic: Any cons to creating potentially millions of scriptObjects?  (Read 792 times)

For my new event pack to replace VCE, I would like to create a separate scriptObject for each variable, simply so I can create functions for each variable 'class' (Numbers, vectors, strings, etc). These variable objects will mostly be created and deleted instantly, but some will remain as a sort of global variable.

Before I start work on this, is there any disadvantages or problems with doing it this way? The only problem i'm expecting is the object ID count to go mental, but this isn't a huge concern (unless some sort of integer overflow happens).

The two alternatives are:
Reuse the scriptObjects. Probably the best solution, but toughest to code.
Or just use variable arrays.
« Last Edit: March 08, 2014, 04:27:30 PM by boodals 2 »

when you delete a thing doesn't the object id go back "into the pool" so it can be reused later? (not necessarily directed at boodals)

Instead of deleting it when you're done with it, just reset all the field values. I don't see how that's difficult.

Instead of deleting it when you're done with it, just reset all the field values. I don't see how that's difficult.
Yeah. Just make a scriptObject::recycle function, like how someone made an AIConnection::recycle function. I put the latter function below if you want to use it as a reference or something.
Code: [Select]
package AIRecycler
{
function GameConnection::onDeath(%cl, %col, %killer, %damageType, %damageArea)
{
if(%cl.getClassName() $= "AIConnection")
{
if(!isObject(AIRecycler))
new SimSet(AIRecycler);
%cl.player.client = "";
if(!%cl.persistent)
%cl.recycle();
}
Parent::onDeath(%cl, %col, %killer, %damageType, %damageArea);
}
};
activatePackage("AIRecycler");

function CreateAIClient(%persistent)
{
if(!isObject(AIRecycler))
{
new SimSet(AIRecycler);
missionCleanup.add(AIRecycler);
}

if(AIRecycler.getCount() != 0)
{
%cl = AIRecycler.getObject(0);
%cl.persistent = %persistent;
AIRecycler.remove(%cl);
return %cl;
}
return new AIConnection() { persistent = %persistent; };
}

//.recycle courtesy of Greek2Me
function AIConnection::recycle(%this)
{
if(isObject(%this.minigame))
%this.minigame.removeMember(%this);

if(isObject(%this.camera))
%this.camera.delete();
if(isObject(%this.player))
%this.player.delete();
if(isObject(%this.tempBrick))
%this.tempBrick.delete();
if(isObject(%this.brickGroup) && %this.brickGroup.client == %this)
%this.brickGroup.client = -1;

%index = 0;
while((%field = %this.getTaggedField(%index)) !$= "")
{
//some fields cannot be changed once set.... Thanks, Badspot.
if(%lastField $= %field)
{
%index ++;
continue;
}
%lastField = %field;
%field = getField(%field,0);

//Prevent people from breaking things
if(%field !$= stripChars(%field," `~!@#$%^&*()-=+[{]}\\|;:\'\",<.>/?"))
{
error("ERROR (AIConnection::recycle): Invalid field! Skipping...");
%index ++;
continue;
}

eval(%this @ "." @ %field SPC "= \"\";");
}

if(!isObject(AIRecycler))
{
new SimSet(AIRecycler);
missionCleanup.add(AIRecycler);
}

AIRecycler.add(%this);
}

-Snip-

Oooh nice. I guess that's what ill be using then.

Just out of curiosity, /title?