Skip to content

Decorating Tasks

Eric McGary edited this page Jan 6, 2013 · 4 revisions

There are three decorators (for, when and where) available for all three types of tasks(simple, parallel, and sequence). If you set a `count` on a task it will itterate for that count total. If you have a `when` method as a task attribute the task will only run when that method returns `true`. And if you have a `while` method the task will continuously run until that method returns `false`.

For Decorator

    var task = new MonkeyBars.Task({
        ...
        count:3,
        performTask:function(){
            ...
        }
        ...
    });

When Decorator

    var task = new MonkeyBars.Task({
        ...
        when:function(){
            return something == true;
        },
        performTask:function(){
            ...
        }
        ...
    });
    

While Decorator

    var task = new MonkeyBars.Task({
        ...
        while:function(){
            return something == false;
        },
        performTask:function(){
            ...
        }
        ...
    });
    

You can double up on decorations, meaning that you could potentially have a when decorator that also has a for or while decorator applied. There are some instances where this will not work though. Because the for and while decorators overwrite the tasks complete method, adding both will result in the while decorator overwriting the for.

Clone this wiki locally