Camaro Posted October 12, 2019 Share Posted October 12, 2019 I'm creating a framework for one script with multiple tasks. Is it feasible to instantiate a separate event executor to run events? Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted October 12, 2019 Share Posted October 12, 2019 (edited) 1 hour ago, camaro 09 said: I'm creating a framework for one script with multiple tasks. Is it feasible to instantiate a separate event executor to run events? What kind of other tasks are you trying to run while running the main task? You could multi-thread: More Info Here Class Spoiler class HelperThread implements Runnable { private volatile boolean run = true; private volatile Script script; public HelperThread(Script script) { this.script = script; } @Override public void run() { while (run) { if (conditionalSleep(() -> script.myPlayer().isAnimating(), 10000, 500)) { if (conditionalSleep(() -> !script.myPlayer().isAnimating(), 10000, 500)) { script.log("No Longer Animating"); } } } } private boolean conditionalSleep(BooleanSupplier condition, int maxTime, int checkTime) { long startTime = System.currentTimeMillis(); while (!condition.getAsBoolean() && (System.currentTimeMillis() - startTime) < maxTime) { try { Thread.sleep(checkTime); } catch (InterruptedException e) { e.printStackTrace(); } } return condition.getAsBoolean(); } public void stop() { this.run = false; } } Usage Spoiler import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(name = "@Test", author = "BravoTaco", version = 0, info = "", logo = "") public class Main extends Script { private HelperThread helperThread; @Override public void onStart() throws InterruptedException { helperThread = new HelperThread(this); new Thread(helperThread).start(); } @Override public int onLoop() throws InterruptedException { log("Main Thread Running!"); return random(1300, 2300); } @Override public void onExit() throws InterruptedException { helperThread.stop(); } } Edited October 12, 2019 by BravoTaco 1 Quote Link to comment Share on other sites More sharing options...