Author Topic: RECOMMENDATION: Use the default 'Stack' class type.  (Read 548 times)

Try running the following code:

Code: [Select]
new scriptObject(myObj) {
    class = Stack;
};

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?

Yes, you have. That seems interesting.

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

Code: [Select]
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] = "";
}

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

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.

That is currect, but then we could just use:
Code: [Select]
function Stack::onAdd(%this) {
    %this.count = 0;
}
function Stack::push(%this, %data) {
    %this.data[%this.count] = %data;
    %this.count++;
}
function Stack::pop(%this) {
    %this.count--;
    %this.data[%this.count] = "";
}

Badspot needs to implement the ArrayList stuff somewhere on TGE's site

The resource for arrays in TorqueScript looked horrific. I'd rather have no arrays as opposed to a really bad implementation.