Jump to content

How do you integrate an API class?


Recommended Posts

Posted (edited)

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...