Jump to content

Help with conditional sleep


Recommended Posts

Posted

For some reason my conditional sleep isn't working how I expect it too, it checks for a widget every 600ms for a 15 second period, but during the checks the widget is visible but goes undetected until it finishes the end of its current sleep, then onLoop obviously brings back the onconditional sleep function which then detects the widget instantly?

 

Example of code - 

 

           RS2Widget Displaydisc = getWidgets().getWidgetContainingText(162, "What name would you like to check");


           new ConditionalSleep(15000, 600) {
                @Override
                public boolean condition() {
                    log("Wait for display input!");
                    return Displaydisc != null && Displaydisc.isVisible();
                }
            }.sleep();

 

Output from logger -

[INFO][Bot #1][01/10 07:22:16 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:17 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:17 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:18 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:18 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:19 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:20 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:20 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:21 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:21 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:22 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:23 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:23 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:24 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:24 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:25 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:26 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:26 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:27 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:27 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:28 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:29 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:29 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:30 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:30 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:31 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:31 AM]: Display input found
[INFO][Bot #1][01/10 07:22:32 AM]: Wait for display input!
[INFO][Bot #1][01/10 07:22:32 AM]: Display input found

As you can see from the logger after the 15 second period is sleep is over on the second loop it finds the Displaydisc instantly every time..

Posted (edited)

Try moving the Widget declaring and instantiation to a lower scope; within the actual conditional sleep :).

Also; please conform to the Java naming conventions :)

new ConditionalSleep(15000, 600) {
    @Override
    public boolean condition() {
       final RS2Widget displayDisc = getWidgets().getWidgetContainingText(162, "What name would you like to check");
       
       return displayDisc != null && displayDisc.isVisible();
    }
}.sleep();

 

Edited by Eagle Scripts
  • Like 1
Posted
47 minutes ago, Eagle Scripts said:

Try moving the Widget declaring and instantiation to a lower scope; within the actual conditional sleep :).

Also; please conform to the Java naming conventions :)


new ConditionalSleep(15000, 600) {
    @Override
    public boolean condition() {
       final RS2Widget displayDisc = getWidgets().getWidgetContainingText(162, "What name would you like to check");
       
       return displayDisc != null && displayDisc.isVisible();
    }
}.sleep();

 

I didn't realise that whilst setting displayDisc it gives the current state of that widget, I thought it would live check the current state during usage...

Thanks for your response & help :)

  • Like 1
Posted
29 minutes ago, Jar said:

I didn't realise that whilst setting displayDisc it gives the current state of that widget, I thought it would live check the current state during usage...

Thanks for your response & help :)

In an attempt to offer an explanation in the form of a question:

There's nothing magical going on here really. When you initialise the displayDisc variable, you are doing just that - giving it a value. However you never reassign this variable, so why would the value change to null?

Apa

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