Jar Posted January 10, 2019 Share Posted January 10, 2019 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.. Quote Link to comment Share on other sites More sharing options...
Eagle Scripts Posted January 10, 2019 Share Posted January 10, 2019 (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 January 10, 2019 by Eagle Scripts 1 Quote Link to comment Share on other sites More sharing options...
ItPoke Posted January 10, 2019 Share Posted January 10, 2019 Think about the condition() as a loop, so you need to keep checking the widget inside that. Just like Eagle points out. 1 Quote Link to comment Share on other sites More sharing options...
Jar Posted January 10, 2019 Author Share Posted January 10, 2019 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 :) 1 Quote Link to comment Share on other sites More sharing options...
Apaec Posted January 10, 2019 Share Posted January 10, 2019 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 Quote Link to comment Share on other sites More sharing options...