Jump to content

Help with conditional sleep


Jar

Recommended Posts

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

Link to comment
Share on other sites

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

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

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

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