Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Trouble with Custom Events

Featured Replies

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 by TheJacob

  • Author

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 by TheJacob

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.