Information about functions

Hi all,

Im really interested in knowing if we can create/define our own functions? if so could some one tell me how to do this.

for example, the first level is using a function called plan(). can i create a function inside of that or is the a feature that allows us to create a function?

Thanks in advance.

Dreay

It looks like the answer is “sort of”.

This is legal:

function myfunc(){
    return 7;
}

if(myfunc() == 7){
    this.moveXY(38,44);
}

If you want your function to call a method or property that would normally require “this”, you’ll need to pass in a reference to the appropriate thang:

function myfunc(thang){
    thang.moveXY(38,44);
}

myfunc(this);

with API protection turned off, you can probably also get away with:

this.myfunc = function (){
    this.moveXY(38,44);
};

this.myfunc();

However, it does look like levels that use plan() instead of chooseAction() might not handle functions properly, probably due to the whole “planable methods” thing.