bap 18 Share Posted February 26, 2021 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 More sharing options...
flipjazz 13 Share Posted February 26, 2021 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 More sharing options...
Hashtag 8671 Share Posted February 26, 2021 Hey, you wouldn't want to mix state framework with nodes. Check out the "AbstractScript versus TaskScript" section here Link to comment Share on other sites More sharing options...
bap 18 Author Share Posted February 26, 2021 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 More sharing options...
Hashtag 8671 Share Posted February 26, 2021 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 More sharing options...
beefsteak 30 Share Posted February 26, 2021 Any idea why my Eclipse is not letting me import org.dreambot.api.script.ScriptManager.State? It says "the import cannot be resolved" Link to comment Share on other sites More sharing options...
Hashtag 8671 Share Posted February 26, 2021 That internal State is not what you want to use. Instead, you create your own State enum: public enum State { BANK, SOMETHING_ELSE; } Link to comment Share on other sites More sharing options...
beefsteak 30 Share Posted March 1, 2021 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 More sharing options...
Hashtag 8671 Share Posted March 1, 2021 13 minutes ago, beefsteak said: having some trouble with my State enum, here is the code in Github. Newbie scripter here, and tips appreciated ty What's the trouble? Link to comment Share on other sites More sharing options...
beefsteak 30 Share Posted March 1, 2021 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.