Jump to content

ConditionalSleep's condition() doesn't work


Sujamma

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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 :) 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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