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
  • Try asking for help in the chatbox
  • [Video]Simple Node Framework Tutorial


    Mad
     Share

    Recommended Posts

    thanks for this cool guide i will use it in my scripts

     

    edit:

     

    can i add u on skype for some quick questions

    Edited by anxiety
    Link to comment
    Share on other sites

    • 1 month later...
    • 2 months later...

    This is great, this is exactly what I need for my script! :D Thanks!


    So one question, inside the class file that's implementing the node method when I call Inventory.isFull, it gives me an error informing me that .isFull cannot be referenced from a static context?

    Link to comment
    Share on other sites

    This is great, this is exactly what I need for my script! :D Thanks!

    So one question, inside the class file that's implementing the node method when I call Inventory.isFull, it gives me an error informing me that .isFull cannot be referenced from a static context?

     

    Hey, I might have an answer for you. Try passing in a reference of the main script to the constructor of each node so that you can use stuff like getInventory() or getCombat(), or whatever you need.

     

    Here's how I'm doing it on my first script:

     

    Main (example):

    public class Main extends AbstractScript {
        private final Node[] nodes = {new CutTree(this), new Bank(this)};  //"this" passes in the script's reference to each node
    
        @Override
        public int onLoop() {
            for (Node node : nodes) {   //loop through the nodes and check if any are valid
                final Node n = node;
                if (n.validate()) {     //find valid node and execute it
                    n.execute();
                    break;              //break so it doesn't try to do two things at once
                }
            }
    
            return Calculations.random(300, 400);
        }
    }
    

    CutTree (example):

    public class Bank implements Node {
        private Main ctx;   //script reference
    
        public Bank(Main ourScript) { //constructor of the Bank class
            this.ctx = ourScript;     //set the reference in the constructor
        }
    
        @Override
        public boolean validate() {
            return !ctx.getInventory().isFull();  //bank when the inventory is full
        }
    
        @Override
        public void execute() {
            //BANK CODE
        }
    }
    

    Now whenever you want to access stuff like getInventory(), you just use ctx.getInventory(). "ctx" is just an abbreviation for context.

     

    Note: I haven't actually tested anything yet, I'm just playing around with coding at this point, but I hope think that the above stuff should work. Hope this helps you :)

     

    EDIT: I tested it, it works :)

    Edited by spectrewiz
    Link to comment
    Share on other sites

    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
     Share

    ×
    ×
    • 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.