Colivar Posted September 14, 2015 Share Posted September 14, 2015 Hi, I`m trying to learn to script in OSbot, I was wondering if anyone could take the time and tell me what I am doing wrong. I get 3 errors that I dont quite understand. Thanks in advance! import org.osbot.rs07.api.LocalWalker; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.api.model.*; @ScriptManifest(author = "", info = "", logo = "", name = "", version = 0) public class test extends Script { @Override public void onStart() { log("Welcome"); } private enum State { idle, walktobank, walktotrees, atbank, attrees } private State getState() { Entity tree = objects.closest("Willow Tree"); Entity booth = objects.closest("Bank Booth"); if (!myPlayer().isAnimating() && (!myPlayer().isMoving() && (tree == null))); return State.attrees; if (!myPlayer().isAnimating() && (!myPlayer().isMoving() && (booth == null))); return State.atbank; if (!myPlayer().isAnimating() && (!myPlayer().isMoving()) && (tree == null) && (inventory.isEmpty())); return State.walktotrees; if (!myPlayer().isAnimating() && !myPlayer().isMoving() && (booth == null) && (inventory.isFull())); return State.walktobank; return State.idle; } public int onLoop() throws InterruptedException { switch (getState()) { case idle: sleep(random(500, 700)); break; case attrees: Entity tree = objects.closest("Willow Tree"); tree.interact("Chop"); break; case walktobank: Entity booth = objects.closest("Bank Booth"); LocalWalker.walk(booth); break; case walktotrees: Entity tree_2 = objects.closest("Willow Tree"); LocalWalker.walk(tree_2); break; } return random(200,300); } public void onExit() { log("Bye"); } } Quote Link to comment Share on other sites More sharing options...
Precise Posted September 14, 2015 Share Posted September 14, 2015 (edited) which lines have errors? or is the script throwing errors? Edited September 14, 2015 by Precise Quote Link to comment Share on other sites More sharing options...
Flamezzz Posted September 14, 2015 Share Posted September 14, 2015 localWalker.walk * Quote Link to comment Share on other sites More sharing options...
Colivar Posted September 14, 2015 Author Share Posted September 14, 2015 ah wow... I feel foolish, thanks. only one error left: private State getState() { Entity tree = objects.closest("Willow Tree"); Entity booth = objects.closest("Bank Booth"); if (!myPlayer().isAnimating() && (!myPlayer().isMoving() && (tree == null))); return State.attrees; if (!myPlayer().isAnimating() && (!myPlayer().isMoving() && (booth == null))); // error: unreachable code return State.atbank; if (!myPlayer().isAnimating() && (!myPlayer().isMoving()) && (tree == null) && (inventory.isEmpty())); return State.walktotrees; if (!myPlayer().isAnimating() && !myPlayer().isMoving() && (booth == null) && (inventory.isFull())); return State.walktobank; return State.idle; } Quote Link to comment Share on other sites More sharing options...
Defeat3d Posted September 14, 2015 Share Posted September 14, 2015 private State getState() { Entity tree = objects.closest("Willow Tree"); Entity booth = objects.closest("Bank Booth"); if (!myPlayer().isAnimating() && !myPlayer().isMoving() && tree == null) return State.attrees; if (!myPlayer().isAnimating() && !myPlayer().isMoving() && booth == null) return State.atbank; if (!myPlayer().isAnimating() && !myPlayer().isMoving() && tree == null && inventory.isEmpty()) return State.walktotrees; if (!myPlayer().isAnimating() && !myPlayer().isMoving() && booth == null && inventory.isFull()) return State.walktobank; return State.idle; } Quote Link to comment Share on other sites More sharing options...
Colivar Posted September 14, 2015 Author Share Posted September 14, 2015 ouch, I guess after messing around too much I screwed up without realising, thanks! ;) Quote Link to comment Share on other sites More sharing options...
FrostBug Posted September 14, 2015 Share Posted September 14, 2015 (edited) hint: if (!myPlayer().isAnimating() && !myPlayer().isMoving() && tree == null) return State.attrees; If the tree is null, there are no trees nearby. And if there are no trees nearby when in the "attrees" state, you'll get an error (NullPointerException) here: case attrees: Entity tree = objects.closest("Willow Tree"); tree.interact("Chop"); <---- NullPointerException because tree is null break; Edited September 14, 2015 by FrostBug Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted September 14, 2015 Share Posted September 14, 2015 ouch, I guess after messing around too much I screwed up without realising, thanks! To elaborate on why you were having those issues: if (x == y); return z; The idea with the if block is that it tests logic. Now, what you want to do after the if block (if it returns true) is to execute all the code in that block. When you use the semicolon, you're effectively terminating the block. It would look something like this: if (x == y) { } return z; //Note how this is outside the block //Any code after here is UNREACHABLE because we already return z So to fix, we remove the semicolons from our if statements to look like this: if (x == y) return z; Which would look more like this: if (x == y) { return z; } //Code here is only executed when (x == y) evaluates to FALSE (or in better words, when (x != y)) Hope this makes some sense Quote Link to comment Share on other sites More sharing options...
Colivar Posted September 15, 2015 Author Share Posted September 15, 2015 Thanks, this is really helpful! 1 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted September 15, 2015 Share Posted September 15, 2015 Thanks, this is really helpful! If you have any more questions feel free to PM me 1 Quote Link to comment Share on other sites More sharing options...