apa Posted April 23, 2015 Posted April 23, 2015 (edited) I was messing around with the conditional sleep class last night and it was very inconsistent. The deviations, intervals and sleep times seemed to have random effects and I couldn't figure out what the problem was. I ended up pretty much rewriting a conditional sleep and now it works how I expected it should. import org.osbot.rs07.script.MethodProvider; public abstract class BotTimer { int maxSleep; int intervalCheck; int deviation; public BotTimer(int maxSleep, int intervalCheck) { this.maxSleep = maxSleep; this.intervalCheck = intervalCheck; deviation = 0; } public BotTimer(int maxSleep, int intervalCheck, int deviation) { this.maxSleep = maxSleep; this.intervalCheck = intervalCheck; this.deviation = deviation; } public boolean sleep() throws InterruptedException { int randSleep; while (maxSleep > 0 && !breakCondition()) { randSleep = MethodProvider.random(intervalCheck - deviation, intervalCheck + deviation); maxSleep -= randSleep; MethodProvider.sleep(randSleep); } return true; } public abstract boolean breakCondition(); } Using it in your bot would still be the same: new BotTimer(5000, 100) { public boolean breakCondition() { return interfaceOnScreen(465, 21, 25); } }.sleep(); This timer would, at a maximum, call the breakCondition() up to 50 times exactly, or until the interface is shown on screen. Whereas, with ConditionalSleep(5000, 100), it would've execute around 1800 times for me. Edited April 23, 2015 by apa
Zebrafon Posted April 23, 2015 Posted April 23, 2015 ur name Which translates to "monkey" in Swedish.
Botre Posted April 23, 2015 Posted April 23, 2015 I like how you used breakCondition() instead of condition() (the API version of that method), makes more sense IMO. Gj
FrostBug Posted April 24, 2015 Posted April 24, 2015 http://prntscr.com/6xcei0 ? sleepTime is not used, for whatever reason.
Twin Posted April 24, 2015 Posted April 24, 2015 ur name I wanna say his name comes from avatar the last air bender but I have no clue.
Joseph Posted April 24, 2015 Posted April 24, 2015 sleepTime is not used, for whatever reason.Oh forreal, so your telling me the Api version is bugged
ni562 Posted January 5, 2016 Posted January 5, 2016 Since conditionalSleep is no longer in the API documentation, is it preferred to use this method? How well does it work compared to the one from the API?
Joseph Posted January 5, 2016 Posted January 5, 2016 Since conditionalSleep is no longer in the API documentation, is it preferred to use this method? How well does it work compared to the one from the API? you don't see it in the api documents but it still part of osbot. example call conditional sleep to have it wait if (getInventory().contains(getEnergy())) { getBank().depositAll(); new ConditionalSleep(2000, 100) { @Override public boolean condition() throws InterruptedException { return getInventory().isEmpty(); } }.sleep(); }