Jueix Posted February 12, 2019 Share Posted February 12, 2019 I'm still new to this so instead of using conditional sleeps all the time I decided to do this code at the top of my file. public final class Sleep extends ConditionalSleep { private final BooleanSupplier condition; public Sleep(final BooleanSupplier condition, final int timeout) { super(timeout); this.condition = condition; } public Sleep(final BooleanSupplier condition, final int timeout, final int interval) { super(timeout, interval); this.condition = condition; } @Override public final boolean condition() throws InterruptedException { return condition.getAsBoolean(); } public static boolean sleepUntil(final BooleanSupplier condition, final int timeout) { return new Sleep(condition, timeout).sleep(); } public static boolean sleepUntil(final BooleanSupplier condition, final int timeout, final int interval) { return new Sleep(condition, timeout, interval).sleep(); } } I get this error in eclipse The public type Sleep must be defined in its own file. I try and run this code and get this error in the log when running. if(inventory.contains(Items)) { if(!myPlayer().isAnimating() || !myPlayer().isMoving()) { inventory.getItem("Knife").interact("Use"); sleep(random(400,2000)); inventory.getItem(Items).interact("use"); Sleep.sleepUntil(() -> !inventory.contains(Items) || getDialogues().clickContinue() || myPlayer().isMoving(), 15000); log("can I continue to cook or no?"); continuecooking = 1; log("Continuein to cook activated."); } } The error in the console when running shows [ERROR][Bot #1][02/12 01:57:38 PM]: Error in bot executor or from Error class (and not Exception)! java.lang.Error: Unresolved compilation problem: at core.Sleep.sleepUntil(Main.java:43) at core.Main.onLoop(Main.java:204) at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(ji:48) at java.lang.Thread.run(Unknown Source) Quote Link to comment Share on other sites More sharing options...
luciuspragg Posted February 12, 2019 Share Posted February 12, 2019 Java doesn't support two public classes in a single .java file. You'll need to put the declaration in a separate .java file. I must ask, this looks a lot more convoluted than just using conditional sleeps, what about them do you not like? Quote Link to comment Share on other sites More sharing options...
liverare Posted February 16, 2019 Share Posted February 16, 2019 On 2/12/2019 at 7:33 PM, luciuspragg said: Java doesn't support two public classes in a single .java file. You'll need to put the declaration in a separate .java file. I must ask, this looks a lot more convoluted than just using conditional sleeps, what about them do you not like? It appears to be using BooleanSupplier which is mostly syntax sugar. That way, instead of doing: new ConditionalSleep(1000) { @Override public boolean condition() throws InterruptedException { return myPlayer().isUnderAttack(); } }.sleep(); His Sleep class wraps it up and reduces it down to just: new Sleep(myPlayer()::isUnderAttack, 1000).sleep(); Or similarly if you call the static methods in the Sleep class. Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted February 16, 2019 Share Posted February 16, 2019 Why claim you've written the sleep class when you clearly haven't. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.