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.

ConditionalSleep's condition() doesn't work

Featured Replies

I am trying to make a script that completes Cook's Assistant. I go to the Lumby Mill to make flour. After taking the grain from the field I want the bot to go to the mill, but the Conditional Sleep sleeps until timeout without detecting that the condition is true. The Conditional Sleep waits until the gate is open. 

Here's the code: 

private boolean GoToMill2(){
        Position preMillPos = new Position(3166, 3300, 0);

        RS2Object gate = objects.closest("Gate");
        if (!IsOpen(gate)){
            gate.interact("Open");
            new ConditionalSleep(5000, 600){
                @Override
                public boolean condition() throws InterruptedException {
                    return IsOpen(gate);
                }
            }.sleep();
        }

        WalkingEvent walk = new WalkingEvent(preMillPos);
        walk.setMinDistanceThreshold(2);
        execute(walk);
        return true;
    }

    private boolean IsOpen(RS2Object object){
        return Arrays.asList(object.getDefinition().getActions()).contains("Close");
    }

All help is appreciated!

Edited by Sujamma

  • Author
13 minutes ago, Lol_marcus said:

The only error I got when running it is that it's missing a "}" after .sleep();. What error are you getting exactly?


private boolean GoToMill2(){
        Position preMillPos = new Position(3166, 3300, 0);

        RS2Object gate = objects.closest("Gate");
        if (!IsOpen(gate)){
            gate.interact("Open");
            new ConditionalSleep(5000, 600){
                @Override
                public boolean condition() throws InterruptedException {
                    return IsOpen(gate);
                }
            }.sleep();
        }

 

 

 

That's weird. I am not getting any errors in IntelliJ when building and I can run the script in the OSBot client. But I have detected my problem. My problem was that ConditionalSleep didn't stop sleeping even though the gate was open. The real culpirt was IsOpen() method . It returns false even though the gate is open. So my question now would be - how do I reliably detect if the gate is open or not?

Edited by Sujamma
Detected was spelled wrong

Edit: the IsOpen function is not for a gate but for the bank I believe.

Try this: 

gate.getDefinition().getActions()).contains("Close")

Then you will know if it is open or not.

Edited by Geeseball

As far as I know WebWalking does all the interaction with objects. Maybe get the coords of where you want your character to go and let WebWalking do the rest?

  • Author
3 minutes ago, Geeseball said:

Why did you make GoToMill2 a boolean and not a void? 

Does this work?


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

        RS2Object gate = objects.closest("Gate");
        if (!IsOpen(gate)){
            gate.interact("Open");
            new ConditionalSleep(5000, 600){
                @Override
                public boolean condition() {
                    return IsOpen(gate);
                }
            }.sleep();
        }

        WalkingEvent walk = new WalkingEvent(preMillPos);
        walk.setMinDistanceThreshold(2);
        execute(walk);
    }

    private boolean IsOpen(RS2Object object){
        return Arrays.asList(object.getDefinition().getActions()).contains("Close");
    }

 

Nope, changing the return type does not work. Right now the code consists entirely of the method GoToMill2() and IsOpen(), so it doesn't really matter what GoToMill2() returns. The problem is with IsOpen() as I recently discovered. I don't know how to reliably detect if a gate is open or not. 

gate.getDefinition().getActions() returns a list of all possible actions that the gate could have. It is not directly related to the instance and what it actually has.

use gate.hasAction("Close")

  • Author
3 minutes ago, Gunman said:

@Sujamma Try this and see what happens. Wonder if something is getting messed up with the Arrays.asList or something.


new ConditionalSleep(5000, 600){
                @Override
                public boolean condition() throws InterruptedException {
                    return gate.hasAction("Close");
                }
            }.sleep();

 

Changed IsOpen(gate) with gate.hasAction("Close") and it still returns false even though the gate is open. 

13 minutes ago, Geeseball said:

Edit: the IsOpen function is not for a gate but for the bank I believe.

Try this: 


gate.getDefinition().getActions()).contains("Close")

Then you will know if it is open or not.

 

2 minutes ago, Camaro said:

gate.getDefinition().getActions() returns a list of all possible actions that the gate could have. It is not directly related to the instance and what it actually has.

use gate.hasAction("Close")

But in some cases this wouldn't work. E.g. if you doing tut island I don't think that it would have close option since the gate closes immediately itself :) 

2 minutes ago, Kramnik said:

 

But in some cases this wouldn't work. E.g. if you doing tut island I don't think that it would have close option since the gate closes immediately itself :) 

Ah that is good to know 😉 thanks!

For know I think my or @Camaro solution should fix @Sujamma problem.

  • Author
16 minutes ago, Lol_marcus said:

As far as I know WebWalking does all the interaction with objects. Maybe get the coords of where you want your character to go and let WebWalking do the rest?

I am using WalkingEvent, because I think that webWalk is using more processing power(or is it?) and should be used for long distances . But if nothing else works I'll use webWalk.

7 minutes ago, Sujamma said:

I am using WalkingEvent, because I think that webWalk is using more processing power(or is it?) and should be used for long distances . But if nothing else works I'll use webWalk.

Yes it uses more processing power. But you can ask yourself wheter it is more convenient to write a separate piece of script for each gate instead of using webwalk. I think it depends on the distance you have to travel including the obstacles.

@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

Edited by progamerz

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.