Hel Posted June 17, 2017 Share Posted June 17, 2017 Been trying to use a ConditionalSleep to check when the trade window opens up, but it seems to just timeout before it even realises that it's actually trading. log("before cond"); log(trade.isCurrentlyTrading()); // returns false, as expected condSleep(10000, 200, trade.isCurrentlyTrading()); log("after cond"); log(trade.isCurrentlyTrading()); // returns true, as expected // also in the class private void condSleep(int timeout, int delay, boolean b) { new ConditionalSleep(timeout, delay) { @Override public boolean condition() throws InterruptedException { return b; } }.sleep(); } Any help would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
Butters Posted June 17, 2017 Share Posted June 17, 2017 You're passing the boolean as false condSleep(10000, 200, trade.isCurrentlyTrading()); This means it will sleep for 10 seconds every time. You need to pass a boolean supplier like so: log("before cond"); log(trade.isCurrentlyTrading()); // returns false, as expected condSleep(10000, 200, () -> trade.isCurrentlyTrading()); log("after cond"); log(trade.isCurrentlyTrading()); // returns true, as expected // also in the class private void condSleep(int timeout, int delay, BooleanSupplier b) { new ConditionalSleep(timeout, delay) { @Override public boolean condition() throws InterruptedException { return b.asBoolean(); } }.sleep(); } Quote Link to comment Share on other sites More sharing options...
Hel Posted June 17, 2017 Author Share Posted June 17, 2017 1 minute ago, nosepicker said: You're passing the boolean as false condSleep(10000, 200, trade.isCurrentlyTrading()); This means it will sleep for 10 seconds every time. You need to pass a boolean supplier like so: log("before cond"); log(trade.isCurrentlyTrading()); // returns false, as expected condSleep(10000, 200, () -> trade.isCurrentlyTrading()); log("after cond"); log(trade.isCurrentlyTrading()); // returns true, as expected // also in the class private void condSleep(int timeout, int delay, BooleanSupplier b) { new ConditionalSleep(timeout, delay) { @Override public boolean condition() throws InterruptedException { return b.asBoolean(); } }.sleep(); } I'm not entirely sure what you're talking about tbh, but the method I use works fine for things such as bank.isOpen(), so I'm still at a loss of why it works for some booleans and not others? Quote Link to comment Share on other sites More sharing options...
Butters Posted June 17, 2017 Share Posted June 17, 2017 (edited) 18 minutes ago, Slut said: I'm not entirely sure what you're talking about tbh, but the method I use works fine for things such as bank.isOpen(), so I'm still at a loss of why it works for some booleans and not others? new ConditionalSleep(timeout, delay) { @Override public boolean condition() throws InterruptedException { return b.asBoolean(); } }.sleep(); This little thing here. It says sleep for a maximum time of TIMEOUT and check every DELAY time if the CONDITION is true. Now when you pass 10000, 200, false as parameters it means that, hey sleep for 10 seconds and check every 200ms if true == false, which will never be true, so it will sleep for 10 seconds. The boolean you pass is a "constant" let's say. Bolean supplier "fetches" the true/false result from the CONDITION whenever it's invoked. So it will check if it's true/false every 200ms in your case. Edited June 17, 2017 by nosepicker 1 Quote Link to comment Share on other sites More sharing options...
Hel Posted June 17, 2017 Author Share Posted June 17, 2017 4 minutes ago, nosepicker said: new ConditionalSleep(timeout, delay) { @Override public boolean condition() throws InterruptedException { return b.asBoolean(); } }.sleep(); This little thing here. It says sleep for a maximum time of TIMEOUT and check every DELAY time if the CONDITION is true. Now when you pass 10000, 200, false as parameters it means that, hey sleep for 10 seconds and check every 200ms if true == false, which will never be true, so it will sleep for 10 seconds. The boolean you pass is a "constant" let's say. Bolean supplier "fetches" the true/false result from the CONDITION whenever it's invoked. So it will check if it's true/false every 200ms in your case. Ah I see! Thanks for your thorough explanation, really helped Quote Link to comment Share on other sites More sharing options...
tumblez Posted June 17, 2017 Share Posted June 17, 2017 Wish I understood this Quote Link to comment Share on other sites More sharing options...