Jump to content

ConditionalSleep's condition() doesn't work


Sujamma

Recommended Posts

1 hour ago, progamerz said:

@Sujamma
It doesn't work because theoretically, it never changes the value of gate again, so it is stored as an old object which is closed, what you can do is use this


new ConditionalSleep(5000, 600) {
    @Override
    public boolean condition() {
        return getObjects().closest(o -> o.getName().equals("Gate")
                && o.getPosition().equals(gate.getPosition()) && !o.hasAction("Open")) != null;
    }
}.sleep();

The way this works, is that it keeps checking every 600ms if the condition is true, here we are trying to find new object which has the same position as the gate which we interacted but is opened

I used your code, but the bot is still standing still for 5 seconds and only then runs to the mill. I'll just leave it as is, the script works anyway. Thanks for the help.  

Link to comment
Share on other sites

15 minutes ago, Sujamma said:

I used your code, but the bot is still standing still for 5 seconds and only then runs to the mill. I'll just leave it as is, the script works anyway. Thanks for the help.  

If you want you can post the code on something like pastebin and i can help, most probs its not from the conditional sleep

Link to comment
Share on other sites

41 minutes ago, Sujamma said:

https://pastebin.com/nLaKc3NX It's my first time using pastebin, so tell me if something's wrong. 

private void GoToMill2() throws InterruptedException {
    Position outsideMill = new Position(3166, 3300, 0);
    Position insideMill = new Position(3166, 3305, 0);

    if (!getMap().canReach(outsideMill)) {
        if (getDoorHandler().handleNextObstacle(outsideMill)) {
            ConditionalSleep2.sleep(5000, 500, () -> getMap().canReach(outsideMill));
        }
    } else {
        WalkingEvent walk = new WalkingEvent(outsideMill);
        execute(walk);
    }

    // OR

    if (!getMap().canReach(outsideMill)) {
        RS2Object gate = getObjects().closest(o -> o.getName().equalsIgnoreCase("Gate") && o.hasAction("Open"));
        if (gate.interact("Open"))
            ConditionalSleep2.sleep(5000, 500, () -> getMap().canReach(outsideMill));
    } else {
        WalkingEvent walk = new WalkingEvent(outsideMill);
        execute(walk);
    }
}

Basically the first method, it tries to use the DoorHandler API, which you pass in the position where you want to go to, and it will handle the obstacles, that will not let it reach the position
https://osbot.org/api/org/osbot/rs07/api/DoorHandler.html

The second method, is you handling the obstacle manually(without using the DoorHandler API)
Both should work, but make sure to only keep one of the both methods.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...