Blockland Forums > Modification Help

RECOMMENDATION: Use the default 'Stack' class type.

Pages: (1/2) > >>

Bauklotz:

Try running the following code:


--- Code: ---new scriptObject(myObj) {
    class = Stack;
};

--- End code ---

If you .dump() the 'myObj' object, you will notice that the "count" variable has automatically been set, and the functions push and pop have been added.

If you run myObj.push(new scriptObject(object).getName());, and dump myObj again, you will notice the following changes:
variable 'count' set to 1
variable 'data0' set to 'object'

Have I said enough yet?

Chrono:

Yes, you have. That seems interesting.

Ephialtes:

This isn't in Blockland/TGE by default - nor is it hard to implement yourself.


--- Code: ---function Stack::onAdd(%this)
{
    %this.count = 0;
}

function Stack::push(%this, %whatever)
{
    %this.data[%this.count] = %whatever;
    %this.count++;
}

function Stack::pop(%this)
{
    %this.count--;
    %this.data[%this.count] = "";
}
--- End code ---


Bauklotz:

I know it isn't in TGE by default, but it is used by the Undo Stack (ctrl+z).

Ephialtes:

The stack class won't be defined before default server scripts are executed, so it's still not a clever idea to rely on it.

Pages: (1/2) > >>

Go to full version