Anyways, I've used this for a few things
function Queue::onAdd(%this)
{
%this.nextOut = 0;
%this.count = 0;
}
function Queue::push(%this, %data)
{
if(%data $= "")
{
echo("Empty value pushed, ignoring");
backtrace();
return;
}
%this.data[%this.count] = %data;
%this.count++;
}
function Queue::pop(%this)
{
if(%this.nextOut >= %this.count)
return "";
else
{
%r = %this.data[%this.nextOut];
%this.data[%this.nextOut] = "";
%this.nextOut++;
return %r;
}
}
function Queue::peek(%this)
{
return %this.data[%this.nextOut];
}
function Queue::getSize(%this)
{
return %this.count - %this.nextOut;
}
function Queue::clear(%this)
{
for(%i=0;%i<%this.count;%i++)
%this.data[%i] = "";
%this.count = 0;
%this.nextOut = 0;
}
Usage:
%queue = new ScriptObject(){ class=Queue; }; //Create a new queue
%queue.push(%data); //Add %data to the queue
%queue.pop(); //Removes and returns next item from the queue
%queue.peek(); //Returns the next item in the queue, without removing it
%queue.getSize(); /Returns the number of items in the queue
%queue.clear(); //remove everything from the queue