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.

How do you integrate an API class?

Featured Replies

Hey folks, I think I understand the purpose of org.osbot.rs07.script.API abstract class but I don't know how to tie everything together in a script. I think it has something to do with the behavior of MethodProvider.exchangeContext, specifically:

Quote

if you want to provide the existing API components to your own extensions you override this method with a call to this method first by calling super.exchangeContext(bot) followed by the initialization of your own components on which you call this method on.

But I'm stuck on understanding what this actually means. For example, here's a Fighter class that extends API (let's say it'll behave similarly to Combat).

public class Fighter extends API {
    public Fighter(Bot bot) {
        exchangeContext(bot);
    }
    @Override
    public void initializeModule() {
        log("Initializing fighter module.");
    }
    // Some example method.
    public String getMyName() {
        return myPlayer().getName();
    }
}

Right now I don't know where initializeModule should be called, or how I hook this class into the existing API framework for that matter. Based on the docs above, I think it has something to do with overriding the exchangeContext method somewhere, but I don't know where:

// This method would be in a class that subclass's MethodProvider (a wrapper, maybe?)
// But a problem might be, how do I get getBot().getMethods() to return a reference 
// to this new method wrapper so I can access getFighter().
@Override
public MethodProvider exchangeContext(Bot bot) {
    super.exchangeContext(bot);
    fighter = new Fighter(bot);
    fighter.initializeModule();
    return this;
}

public Fighter getFighter() {
    return fighter;
}

Does anyone have those answers? In my mind, the desired end state is something like:

@Override
public int onLoop() {
    String myName = getBot().getMethods().getFighter().getMyName();
    // or maybe just getFighter().getMyname() for short, similar to getCombat().
    // ...
    return 600;
}

Edited by TheJacob

  • Author

Solution:

I don't think I understood the reasons to extend API vs. MethodProvider, and how exchangeContext ties in with Bot. This post explains it quite well:

 

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.