Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Learning TaskScript after using AbstractScript


    Doxial

    Recommended Posts

    I've made a couple AbstractScripts and I understand how they work and their flow, such as needing onStart(), onLoop(), etc... however there seems to be much less informative content about TaskScript so I'm struggling trying to learn what all is needed in it and it's "flow". I've read Hashtags 'Scripting 101 Guide' however that just details the differences in them, and not the how they work in detail, still a great guide nonetheless. I was wondering if anyone had any links to tutorials over them I may of somehow missed? Or if someone can give the cliff notes of what is needed in a TaskScript?

    Link to comment
    Share on other sites

    I personally skipped taskscript and went straight to treescript. Regardless i would suggest you look at open source repos on github. just search "dreambot" with java as language and sort by newest

    Link to comment
    Share on other sites

    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:

    1. boolean accept() - this is the condition that must be met in order to trigger the TaskNode.
    2. int execute() - think of your AbstractScript's onLoop(). This executes the actions/logic we actually want to perform.
    3. 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.
    Link to comment
    Share on other sites

    • 1 month later...

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.