TheJacob Posted January 23, 2023 Share Posted January 23, 2023 (edited) Hey folks, I'm writing a custom Event and the MethodProvider 'execute' method doesn't provide my event to the engine for execution. I expect "Running event." to be output in the OSBot client logger; however, nothing is output. // Events.java public class MyEvent extends Event { @Override public int execute() { log("Running event."); // Debug info. return -1; // Immediately stops. } } // MyScript.java // // in @onStart this.myEvent = new MyEvent(); //this.myEvent.exchangeContext(getBot()); **See follow-up** // in @onLoop execute(this.myEvent); return 20000; // to avoid repeated executions. Follow-up: I shouldn't call exchangeContext in @onStart because Event is a subclass of MethodProvider. That said, when I remove that call, I now run into a different issue where "Running event." is continuously output to the OSBot client logger rather than once. I expected it to be output once because I return -1 in myEvent.execute. Does anyone know how to solve that? Follow-up: If I set the return value from -1 to 2000, then it behaves as expected (outputting "Running event." every 2000ms to OSBot client logger). So, I *think* my question is, how do I properly flag that my event is ready for termination? Edited January 23, 2023 by TheJacob Quote Link to comment Share on other sites More sharing options...
TheJacob Posted January 23, 2023 Author Share Posted January 23, 2023 (edited) Solution: In order to properly flag a subclass of Event for termination, you must call "setFinished". Complete code: // MyScript.java // // @onLoop execute(new MyEvent()); // MyEvent.java public class MyEvent extends Event { public MyEvent() { } public int execute() { // Do stuff // ... // Ready to finish. setFinished(); return 0; } } Thank you @Gunman for referring me to this thread below as API Docs for execute confused me (lead me to believe a negative number returned would terminate the Event). Edited January 23, 2023 by TheJacob 1 Quote Link to comment Share on other sites More sharing options...