R I F T Posted November 30, 2018 Share Posted November 30, 2018 (edited) I'm writing a sand crab script and before I run to the correct position to begin afking, I want to walk to an area first. I run to the area fine, but when I try and walk to the specific position, I get stuck in an infinite loop as getWalking().walk(desiredPosition) is falsely returning true. It always leaves me about 2-3 tiles away. private Area currentArea; private Position currentSpot; ... private void takeSpot() { currentArea = spotManager.freeArea(); currentSpot = spotManager.freeSpot(); log("Found a spot at " + currentSpot.toString()); log("Taking spot ..."); while(!currentArea.contains(myPlayer())) { log("Moving to area ..."); getWalking().walk(currentArea); new Sleep(() -> myPlayer().isMoving(), 6000).sleep(); sleep(200); } log("Moved to area!"); log("Current position: " + myPlayer().getPosition().toString()); log("Desired position: " + currentSpot.toString()); while(myPlayer().getPosition() != currentSpot) { log("Moving to position"); log("Current position: " + myPlayer().getPosition().toString()); log("Desired position: " + currentSpot.toString()); log("Result of attempting to walk to position is: " + getWalking().walk(currentSpot)); getWalking().walk(currentSpot); new Sleep(() -> !myPlayer().isMoving(), 3000).sleep(); } } Example outputs of logs: [INFO][Bot #1][11/30 07:41:28 PM]: Moving to position [INFO][Bot #1][11/30 07:41:28 PM]: Current position: [x=1696, y=3470, z=0] [INFO][Bot #1][11/30 07:41:28 PM]: Desired position: [x=1695, y=3471, z=0] [INFO][Bot #1][11/30 07:41:28 PM]: Result of attempting to walk to position is: true [INFO][Bot #1][11/30 07:41:28 PM]: Moving to position [INFO][Bot #1][11/30 07:41:28 PM]: Current position: [x=1696, y=3470, z=0] [INFO][Bot #1][11/30 07:41:28 PM]: Desired position: [x=1695, y=3471, z=0] [INFO][Bot #1][11/30 07:41:28 PM]: Result of attempting to walk to position is: true [INFO][Bot #1][11/30 07:41:28 PM]: Moving to position [INFO][Bot #1][11/30 07:41:28 PM]: Current position: [x=1696, y=3470, z=0] [INFO][Bot #1][11/30 07:41:28 PM]: Desired position: [x=1695, y=3471, z=0] [INFO][Bot #1][11/30 07:41:28 PM]: Result of attempting to walk to position is: true It says that the call to getWalking().walk(currentSpot) is true, however I'm still 2-3 squares away. I can move into the area containing this spot fine, but get stuck in an infinite loop in my second while loop. I'm only using a static sleep(200) for debugging, as the client crashes otherwise. I'm new to scripting and a Java nooblet, so any help is welcomed Edited November 30, 2018 by R I F T Quote Link to comment Share on other sites More sharing options...
jca Posted November 30, 2018 Share Posted November 30, 2018 (edited) getWalking().walk(Position p); Has a minimum distance threshold greater than zero, so if you’re within the threshold (I’m not 100% what it is) the event is considered successful. You need a custom walk event. WalkingEvent myWalk = new WalkingEvent(Position p); myWalk.setMinDistanceThreshold(0); execute(myWalk); Also you should restructure to avoid while() loops. Edited December 1, 2018 by jca 3 Quote Link to comment Share on other sites More sharing options...
Juggles Posted November 30, 2018 Share Posted November 30, 2018 Like @jca said, if you've don't restrict the event, then it will count as you're in the zone if you're within 2-3 tiles of the area. Quote Link to comment Share on other sites More sharing options...
R I F T Posted November 30, 2018 Author Share Posted November 30, 2018 17 minutes ago, jca said: getWalking().walk(Position p) has a minimum distance threshold greater than zero, so if you’re within the threshold (I’m not 100% what it is, the event considered successful. You need a custom walk event. WalkingEvent myWalk = new WalkingEvent(Position p); myWalk.setMinDistanceThreshold(0); execute(myWalk); Easy fix. Thanks so much! Quote Link to comment Share on other sites More sharing options...
jca Posted November 30, 2018 Share Posted November 30, 2018 29 minutes ago, R I F T said: Easy fix. Thanks so much! No problem! Quote Link to comment Share on other sites More sharing options...