Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Result of walking to position is returning true on failure

Featured Replies

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 by R I F T

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 by jca

  • Author
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!

29 minutes ago, R I F T said:

Easy fix. Thanks so much!

No problem!

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.