Jump to content

ConditionalSleep's condition() doesn't work


Recommended Posts

Posted
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.  

Posted
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

Posted
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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