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
  • Best way to do script states and getting current node


    bap
     Share

    Recommended Posts

    Currently the way I do my states is like this

    States.java

    public enum States {
        NOTHING("Nothing"),
        ATTACKING("Attacking"),
        WALKING("Walking");
    
        private String state;
        States(String state) {
            this.state = state;
        }
    
        public String getState() {
            return state;
        }
    }

    Main.java

    public static States state = States.NOTHING;
    
    
    public void onPaint(Graphics2D g) {
        g.drawString("State: " + state.getState() + " - " + npc.getName() ,12,77);
    }

    AttackCows.java

    Main.state = States.ATTACKING;

     

    Is there a better way to do this? As well as getting what node I'm currently on?

     

    Thanks! :) 

    Link to comment
    Share on other sites

    I'm pretty new to scripting, so not sure if i'm right...

    I think if you're using the TaskNode/TaskScript stuff, maybe you can avoid using the States enum. just use the TaskNode to be your "state"

    You'll have several TaskNodes that get run like AttackCowTaskNode or WalkingTaskNode. Then you can use getLastTaskNode() to get the task node you were just on.

    public void onPaint(Graphics2D g) {
        TaskNode previousNode = getLastTaskNode();
       
        // Then fill in the blank with the task node. Maybe give
        // it a new toString() method, so you can just print it out directly.
        g.drawString("State: " + previousNode.toString() + " - " + npc.getName() ,12,77);
    }

     

    Link to comment
    Share on other sites

    10 hours ago, Hashtag said:

    Hey, you wouldn't want to mix state framework with nodes. Check out the "AbstractScript versus TaskScript" section here 

     

    It's not really mixing them, it's just the paint and what not to see what action I'm currently doing

    Link to comment
    Share on other sites

    Oh seems like I misinterpreted the situation. You want to keep a reference to the previous state that was executed. With TaskScript you can achieve that with what @flipjazz posted. If you're not willing to use TaskScript, then you want to manually store the state in a var. For example

    private State state;
    
    public int onLoop() {
      state = getState();
      switch (state) {
        case BANK:
          
          break;
        case SOMETHING_ELSE:
          
          break;
      }
    }
    
    public State getState() {
      if (...) {
        return State.BANK;
      } else {
        return State.SOMETHING_ELSE;
      }
    }
    
    public void onPaint(Graphics2D g) {
      g.drawString("State: " + state.toString(), x, y);
    }

     

    Link to comment
    Share on other sites

    On 2/26/2021 at 12:40 PM, Hashtag said:

    That internal State is not what you want to use. Instead, you create your own State enum:

    public enum State {
      BANK, SOMETHING_ELSE;
    }

     

    having some trouble with my State enum, here is the code in Github.  Newbie scripter here, and tips appreciated ty

    Link to comment
    Share on other sites

    25 minutes ago, Hashtag said:

    What's the trouble?

    lines 53 and 57 say "Type mismatch: cannot convert from String to Zmonks.State" 
    line 68 "state cannot be resolved to a variable" (guessing because of line 53, 57 errors)

    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.