Michaudretard 0 Share Posted August 30, 2020 Treebot are build with branch and leaf. First we have to create our root task in our main.java file. Then we return where our bot should start. In this case the bot should start at looking if inventory contain the ingredients. public class main extends TreeBot { private final inv_ingredient_check invIngredientCheck = new inv_ingredient_check(); @Override public TreeTask createRootTask() { return invIngredientCheck; } } Branch are boolean build like this. We have the validate state that look for the true or false and we have the return statement (success and the failure). In this code we are looking if the bank contains grapes and jug of water. If the bank contains those item we return a success task and move on a branch task again or a leaf that execute code base on the true or false statement. If the bank doesn't contain those item we return the failure task and move on a branch task again or a leaf that execute code base on the true or false statement. public class bank_contain_ingredient extends BranchTask { private final inv_contain_something invContainSomething = new inv_contain_something(); private final is_bank_close isBankClose = new is_bank_close(); @Override public boolean validate() { return Bank.containsAllOf("Grapes", "Jug of water"); } @Override public TreeTask successTask() { return invContainSomething; } @Override public TreeTask failureTask() { return isBankClose; } } Leaf execute code base on the returned boolean. public class close_bank extends LeafTask { @Override public void execute() { Bank.close(); } } Link to comment Share on other sites More sharing options...
None 227 Share Posted August 31, 2020 On 8/29/2020 at 11:06 PM, Michaudretard said: Treebot are build with branch and leaf. First we have to create our root task in our main.java file. Then we return where our bot should start. In this case the bot should start at looking if inventory contain the ingredients. public class main extends TreeBot { private final inv_ingredient_check invIngredientCheck = new inv_ingredient_check(); @Override public TreeTask createRootTask() { return invIngredientCheck; } } Branch are boolean build like this. We have the validate state that look for the true or false and we have the return statement (success and the failure). In this code we are looking if the bank contains grapes and jug of water. If the bank contains those item we return a success task and move on a branch task again or a leaf that execute code base on the true or false statement. If the bank doesn't contain those item we return the failure task and move on a branch task again or a leaf that execute code base on the true or false statement. public class bank_contain_ingredient extends BranchTask { private final inv_contain_something invContainSomething = new inv_contain_something(); private final is_bank_close isBankClose = new is_bank_close(); @Override public boolean validate() { return Bank.containsAllOf("Grapes", "Jug of water"); } @Override public TreeTask successTask() { return invContainSomething; } @Override public TreeTask failureTask() { return isBankClose; } } Leaf execute code base on the returned boolean. public class close_bank extends LeafTask { @Override public void execute() { Bank.close(); } } Yeah... this already exists. Extend TaskScript on your main class and TaskNode on your Nodes Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.