evert123 Posted September 27, 2017 Share Posted September 27, 2017 Hello guys, I read Apaec's guide: "A beginners guide to writing OSbot scripts" and got excited to use enum with switch. So I'm exploring this method but get weird results, I will try to explain as clearly as I can. What (I think) my script is supposed to be doing right now: Check if within the area If not walk to sellpoint, send message "walking back" Check if more than 1 law rune in inventory If true send message "test" What is happening when the script is run: When my player is in the area it spams "walkinig back" but is not walking back When my player is NOT in the area it walks back and is not spamming "walking back" private final Area lumbyBank = new Area(3207, 3217, 3210, 3220); Position sellPoint = new Position (3208, 3217, 2); private enum State { WALK, TRADE, EXIT } private State getState() { if (!lumbyBank.contains(myPosition())) return State.WALK; if (getInventory().getItem("Law rune").getAmount() >= 1) return State.TRADE; return State.EXIT; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case WALK: getWalking().walk(sellPoint); log("walk back"); break; case TRADE: log("test"); break; case EXIT: stop(); break; } return random(200, 300); } Quote Link to comment Share on other sites More sharing options...
Explv Posted September 27, 2017 Share Posted September 27, 2017 (edited) 5 minutes ago, evert123 said: Hello guys, I read Apaec's guide: "A beginners guide to writing OSbot scripts" and got excited to use enum with switch. So I'm exploring this method but get weird results, I will try to explain as clearly as I can. What (I think) my script is supposed to be doing right now: Check if within the area If not walk to sellpoint, send message "walking back" Check if more than 1 law rune in inventory If true send message "test" What is happening when the script is run: When my player is in the area it spams "walkinig back" but is not walking back When my player is NOT in the area it walks back and is not spamming "walking back" private final Area lumbyBank = new Area(3207, 3217, 3210, 3220); Position sellPoint = new Position (3208, 3217, 2); private enum State { WALK, TRADE, EXIT } private State getState() { if (!lumbyBank.contains(myPosition())) return State.WALK; if (getInventory().getItem("Law rune").getAmount() >= 1) return State.TRADE; return State.EXIT; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case WALK: getWalking().walk(sellPoint); log("walk back"); break; case TRADE: log("test"); break; case EXIT: stop(); break; } return random(200, 300); } Firstly your Lumbridge bank area is incorrect, I would recommend you use the constant Banks.LUMBRIDGE_UPPER instead. Secondly your logic in general seems weird. I would recommend not using the state pattern because it just confuses things. Edited September 27, 2017 by Explv Quote Link to comment Share on other sites More sharing options...
evert123 Posted September 27, 2017 Author Share Posted September 27, 2017 5 minutes ago, Explv said: Firstly your Lumbridge bank area is incorrect, I would recommend you use the constant Banks.LUMBRIDGE_UPPER instead. Secondly your logic in general seems weird. I would recommend not using the state pattern because it just confuses things. Thank you very much, nice response time to I will try a different method and do some figuring out myself Quote Link to comment Share on other sites More sharing options...