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
  • TreeScript isValid() not working as intended?


    ImLife

    Recommended Posts

    Hello scripters!
    Bernie I Am Once Again Asking For Your Support Meme Generator

    I am once again asking for your assistance!

     

     

    I am trying to learn the Tree branch architecture, however the isValid() method does not seem to work as described in the documentation:

    image.thumb.png.0a5edd982b4fa92a0b27bc2fa0db0902.png

     

    My thoughts are that if a branch is valid it should run the leaf if the leaf is valid. Basically a double if statement:

    As seen below:

    BranchOne = true
    LeafOne=false
    LeafTwo= true

    BranchOne: run
     - LeafOne: do not run
     - LeafTwo: run

     

    However, this is my code and it never runs the Leaf node "DoWalkTreeArea"

     

    public class DoWalkTreeArea extends Leaf {
    
    
        @Override
        public boolean isValid() {
            return true;
        }
    
        @Override
        public int onLoop() {
            Logger.log("Looping do walk tree area");
            Tile closestTile = WillowArea.getNearestTile(Players.getLocal());
            Walking.walk(closestTile);
            Sleep.sleepUntil(() -> Players.getLocal().isMoving(), 1000, 200);
            return 1000;
        }
    }

     

     

    public class WalkTreeArea extends Branch {
    
        @Override
        public boolean isValid() {
            return true;
        }
    
    }

     

    @ScriptManifest(name = "test", version = 1, author = "ImLife", category = Category.WOODCUTTING)
    public class Main extends TreeScript {
    
        @Override
        public void onStart() {
                  addBranches(new WalkTreeArea()).addLeaves(new DoWalkTreeArea());
        }
    
        @Override
        public int onLoop() {
            Logger.log("Looping main loop");
            return this.getRoot().onLoop();
        }
    }

     

    The code never logs "Looping do walk tree area". why is that?

    Note: it works if I set everything to false

    Link to comment
    Share on other sites

    Posted (edited)

    After 5 hours... Kill me

    Fixed parentheses: 

        @Override
        public void onStart() {
                  addBranches(new WalkTreeArea()).addLeaves(new DoWalkTreeArea());
        }

     

        @Override
        public void onStart() {
                  addBranches(new WalkTreeArea().addLeaves(new DoWalkTreeArea()));
        }

     

     

    Edited by ImLife
    added more code
    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
    ×
    ×
    • 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.