ultraswagger Posted February 6, 2020 Share Posted February 6, 2020 Hi all, So I'm experiencing an issue where my ConditionalSleep isn't blocking the execution of onLoop. For example this snippet below should sleep until my inventory only contains one kind of item. log("OnLoop has been run again"); new ConditionalSleep(Integer.MAX_VALUE) { public boolean condition() throws InterruptedException { return inventory.onlyContains('something'); } }.sleep(); But the logger shows that onLoop is being repetitively called. Am I misunderstanding how ConditionalSleep works here? If so what is the correct way of blocking my script from running. Quote Link to comment Share on other sites More sharing options...
Naked Posted February 6, 2020 Share Posted February 6, 2020 onLoop is basically a while(true) loop. It's the core of the script. It runs repeatedly until the script is stopped. ConditionalSleep is used to sleep until an action happens. I know a lot of people use this class for conditional sleeps: So to drop something, you may do: if(inventory.drop(itemId)) { Sleep.sleepUntil(() -> !inventory.contains(itemId), 2000); Thread.sleep(MethodProvider.random(100, 400)); } It really cleans it up. Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted February 6, 2020 Share Posted February 6, 2020 (edited) Hmmm interesting is this directly in the onLoop() or are you calling it from somewhere? Also I noticed that if the inventory is completely empty than inventory.onlyContains() method will return true. Try this: new ConditionalSleep(Integer.MAX_VALUE) { @Override public boolean condition() throws InterruptedException { return !getInventory().isEmpty() && getInventory().onlyContains("Something"); } }.sleep(); Edited February 6, 2020 by BravoTaco 1 Quote Link to comment Share on other sites More sharing options...
Tom Posted February 6, 2020 Share Posted February 6, 2020 A few things to note Make sure you calling the ConditionalSleep within the main thread, if you didn't create a new thread you dont have to worry about this. Don't conditional sleep for the max duration, thats how your script gets stuck in the future and never recovers Make sure the condition isnt evaluating to true, you may think it behaves in a certain way but theres every possibility that it doesnt, and you will need to add extra conditions Quote Link to comment Share on other sites More sharing options...
ultraswagger Posted February 7, 2020 Author Share Posted February 7, 2020 13 hours ago, BravoTaco said: Hmmm interesting is this directly in the onLoop() or are you calling it from somewhere? Also I noticed that if the inventory is completely empty than inventory.onlyContains() method will return true. Try this: new ConditionalSleep(Integer.MAX_VALUE) { @Override public boolean condition() throws InterruptedException { return !getInventory().isEmpty() && getInventory().onlyContains("Something"); } }.sleep(); Turns out this was the issue , getInventory.onlyContains was returning True when my inventory was empty. Looks like I didn't look at it thoroughly enough since the api for it does say "This method does not require that all the specified items exist, it determines whether there are no other items in the container". Thanks for the help guys! Quote Link to comment Share on other sites More sharing options...