Jump to content

How do you integrate an API class?


TheJacob

Recommended Posts

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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