-
Notifications
You must be signed in to change notification settings - Fork 0
Runtime Insertion
Eric McGary edited this page Jan 6, 2013
·
1 revision
There may be times where you only want to add a task only if another exceeds. There may also be cases where you want to remove a task in a group if another succeeds or fails. There are a number of methods available to task groups that make this possible.
-
addSubTask
- Use this method to add a subtask to the end of a groups queue. You can either pass an already instantiated task or a JSON representation of a task.
- Example:
var group = new MonkeyBars.SequenceTask({ ... }); group.start(); group.addSubTask({ id:"custom", performTask:function(){ ... } }); var custom2 = new MonkeyBars.Task({ id:"custom2", performTask:function(){ ... } }); group.addSubTask(custom2);
-
addSubTaskAfterTask
- Use this method to add a subtask after one already in the groups queue. The method takes two arguments, the first being the task to be added, which can be an already instantiated task or a JSON representation of a task. The second argument is a reference to the task object which you want to add the new task after.
If you do not have direct access to the task that you're wanting to add after you can you the task retrival methods
getTaskByTid
,getTaskById
orgetTaskByName
(read more about these in the docs directory). - Example:
var group = new MonkeyBars.SequenceTask({ tasks:[{ id:"t1", performTask:function(){ if(true){ this.group.addSubTaskAfterTask({ id:"t2", performTask:function(){ ... } },this); } this.complete(); } }] }); group.start();
- Use this method to add a subtask after one already in the groups queue. The method takes two arguments, the first being the task to be added, which can be an already instantiated task or a JSON representation of a task. The second argument is a reference to the task object which you want to add the new task after.
If you do not have direct access to the task that you're wanting to add after you can you the task retrival methods
-
addSubTaskBeforeTask
- This method acts very similarly to the
addSubTaskAfterTask
method, but rather than added a task after another task it adds it before. It is important to note though that if the task you are adding the new task before has already completed then the added task will never be run and the group will not complete.
- This method acts very similarly to the
-
removeSubTask
- It is possible to remove a sub task from a groups queue. This method takes one argument, a reference to the task instance you're wanting to remove. Use the retrival methods, on the group the task belongs to, (perviously shown) to get a task reference if you do not have direct access to it.