TaskScript uses TaskNodes to perform your script's function. Instead of managing your script's logic within the main onLoop(), you will create several TaskNodes to break up the script into different tasks
TaskNodes have three methods associated with them:
boolean accept() - this is the condition that must be met in order to trigger the TaskNode.
int execute() - think of your AbstractScript's onLoop(). This executes the actions/logic we actually want to perform.
int priority() - allows you to prioritize your TaskNodes. By default, TaskScript will iterate through your TaskNodes in the order you add them.
The script will iterate through each task (either in priority order high to low, or in order that they've been added). If the accept() condition is found to be valid, the script will loop through that TaskNode's execute().
I will use a basic woodcutting script as an example. In the onStart() of our main class, we will need to add our nodes:
@Override
public void onStart() {
addNodes(new BankTask(), new DropTask(), new ChopTask());
}
First the script would iterate through our BankTask. So long as the conditions of accept() are found to be true, we will loop through BankTask.execute(). Once we've deposited our logs, this TaskNode will no longer be true (inventory is NOT full) and the script will move onto the next TaskNode:
public class BankTask extends TaskNode {
@Override
public boolean accept() {
return Inventory.isFull() && !isDrop; //isDrop is an internal boolean determined by the user within the GUI
}
@Override
public int execute() {
//Logic for Banking & depositing logs
return 1000;
}
}
Then the script would iterate through your DropTask, depending on the state of boolean isDrop:
public class DropTask extends TaskNode {
@Override
public boolean accept() {
return Inventory.isFull() && isDrop; //isDrop is an internal boolean determined by the user within the GUI
}
@Override
public int execute() {
//Logic for Dropping inventory of logs
return 1000;
}
}
If neither of our above TaskNodes return a valid accept() condition, the script would move onto the ChopTask(). In this example, I left the accept() as true since I know the script will only get to this node, if DropTask & BankTask are NOT valid. You're welcome to add a condition to be met (for example, verifying treeArea.contains(Players.getLocal()) )
public class ChopTask extends TaskNode {
@Override
public boolean accept() {
return true;
}
@Override
public int execute() {
//Logic for Walking to the tree location & chopping desired tree
return 1000;
}
}
Once you've flushed out the execute() logic in each, and add your nodes in the Main class onStart(), TaskScript will handle the rest.
It will loop through BankTask>DropTask>ChopTask, checking to see which one returns accept() first, and then run the appropriate execute()
If you so choose, you could break out the script logic into even more tasks (Bank, Drop, Travel, Chop, Idle). Some people may find this excessive. Do whatever you find easiest. I personally like breaking down my script into smaller tasks and will opt to use either TaskScript or TreeScript. Similar to the previous poster, I learned using TreeScript at first (specifically this implementation), but I do find it overkill for simple scripts and have been using TaskScript far more often now.
In TaskScript, your script logic is executed within each TaskNode. The script will check Task accept() > Task execute() if valid
In TreeScript, your script logic is executed within each Leaf, which are stored in Branches. The script will check the Branch accept() > check the Leaf accept() if valid > Leaf execute() if valid.