gumibearscuz Posted July 25, 2019 Posted July 25, 2019 I have a fairly simple script that I was testing and I realized all of my ConditionalSleeps are just timing out. E.g. RS2Widget widget = api.getWidgets.get(270, 14); if (widget != null) { if (widget.interact("Make")) { boolean result = new ConditionalSleep(10000, 16000) { @Override public boolean condition() throws InterruptedException { api.log("Vial amount: " + api.getInventory().getAmount("Vial of water"); api.log("Herb amount: " + api.getInventory().getAmount("Ranarr weed"); return api.getInventory().getAmount("Vial of water") == 0 || api.getInventory().getAmount("Ranarr weed") == 0; } }.sleep(); api.log("ConditionalSleep returned: " + result); } } Results in logging "Vial amount: 14" "Herb amount: 14" "ConditionalSleep returned: false" every time. It doesn't even check the condition more than once.
Hybris Posted July 25, 2019 Posted July 25, 2019 10 hours ago, gumibearscuz said: I have a fairly simple script that I was testing and I realized all of my ConditionalSleeps are just timing out. E.g. RS2Widget widget = api.getWidgets.get(270, 14); if (widget != null) { if (widget.interact("Make")) { boolean result = new ConditionalSleep(10000, 16000) { @Override public boolean condition() throws InterruptedException { api.log("Vial amount: " + api.getInventory().getAmount("Vial of water"); api.log("Herb amount: " + api.getInventory().getAmount("Ranarr weed"); return api.getInventory().getAmount("Vial of water") == 0 || api.getInventory().getAmount("Ranarr weed") == 0; } }.sleep(); api.log("ConditionalSleep returned: " + result); } } Results in logging "Vial amount: 14" "Herb amount: 14" "ConditionalSleep returned: false" every time. It doesn't even check the condition more than once. Look into using this: & write your code something like this: if (widget != null) { if (widget.interact("Make")) { api.log("Vial amount: " + api.getInventory().getAmount("Vial of water"); api.log("Herb amount: " + api.getInventory().getAmount("Ranarr weed"); Sleep.sleepUntil(()-> api.getInventory().getAmount("Vial of water") == 0 || api.getInventory().getAmount("Ranarr weed") == 0, 20000); api.log("ConditionalSleep returned: " + result); } }
DylanSRT Posted July 25, 2019 Posted July 25, 2019 Second Hybris' comment. I've been using Explv's Sleep Class in everything and it works great and keeps your script concise