TheJacob Posted January 25, 2023 Share Posted January 25, 2023 (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 January 25, 2023 by TheJacob Quote Link to comment Share on other sites More sharing options...
TheJacob Posted January 25, 2023 Author Share Posted January 25, 2023 (edited) 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 January 25, 2023 by TheJacob 1 Quote Link to comment Share on other sites More sharing options...