PineappleSausage Posted January 10, 2017 Share Posted January 10, 2017 (edited) Hi, I am new to this API and bot scripting in general (not to coding though) and I'm unsure of how to accomplish using multiple scripts. I'm trying to use something like a "main" Script as an overarching entry point, which can call other Scripts in sequential order. This way, I could implement modular Scripts. So in my "main" script I have this: @[member='Override'] public int onLoop() throws InterruptedException { Script tinCopperMiner = new TinCopperMiner(); // TinCopperMiner is a local script Bot bot = this.getBot(); bot.getScriptExecutor().prepare(tinCopperMiner); bot.getScriptExecutor().start(tinCopperMiner); // call more local scripts as needed this.stop(); return 0; } The inner, modular Scripts would be responsible for calling stop(). This doesn't seem to work though (null pointer exception), probably am misusing the API... Edited January 10, 2017 by PineappleSausage Quote Link to comment Share on other sites More sharing options...
PlagueDoctor Posted January 10, 2017 Share Posted January 10, 2017 (edited) Edited as i misread the post. ~ AFAIK It is possible to switch which script you're running on a OSBot client through the API. However it's not possible to start another OSBot client from within a osbot script (I tried this in the past. It's against the rules). A way you could accomplish this would be to write a socket that executes scripts and closes scripts depending on messages it receives from the client. This would require a reasonable bit of coding prowess and creativity, but as you've stated that you're not new to coding perhaps this idea might be relevant to you. Edit 12637883533: Creating a script manager that used modular coding would be fucking awesome though. Edited January 10, 2017 by PlagueDoctor Quote Link to comment Share on other sites More sharing options...
PineappleSausage Posted January 10, 2017 Author Share Posted January 10, 2017 (edited) Hm okay... Well I thought of a fairly easy way to still create modular scripts. Just need to separate out the implementation. TinCopperMiner: public class TinCopperMiner extends Script { private TinCopperMinerImpl tinCopperMinerImpl; @[member='Override'] public void onStart() { TinCopperMinerImpl tinCopperMiner = new TinCopperMinerImpl(this); } @[member='Override'] public int onLoop() throws InterruptedException { TinCopperMinerImpl.execute(); this.stop(); return 0; } @[member='Override'] public void onExit() {} } TinCopperMinerImpl (the actual implementation): public class TinCopperMinerImpl { Script parentScript; public TinCopperMinerImpl(Script script) { // still have access to the Script's API via this constructor arg parentScript = script; } // psuedo-code-y public void start() { setup(); while (some condition is true) { loop(); } exit(); } // some methods similar to what you'd override in the Script class private void setup() private int loop() private void exit() } The "main" entry Script I talked about would then call out to individual implementations not Scripts: @[member='Override'] public int onLoop() throws InterruptedException { TinCopperMinerImpl tinCopperMinerImpl = new TinCopperMinerImpl(this); tinCopperMinerImpl.execute(); // call more executes of other Script implementations as needed this.stop(); return 0; } Pretty hack-y and I'm not 100% sure this will work. But if it does work, it would allow me to use TinCopperMiner as a Script on its own, or use its implementation in a different script. Is there some other, better way to create modular code? Or maybe a tool which lets you run Scripts back to back (which is basically all I want to be able to do)? I'm just trying to keep code modular for readability and efficiency purposes. I stumbled upon a tutorial island script here on this site which had a switch statement in its onLoop with several hundred cases... definitely trying to avoid that. Edited January 10, 2017 by PineappleSausage Quote Link to comment Share on other sites More sharing options...
Abuse Posted January 10, 2017 Share Posted January 10, 2017 (edited) When I started writing my scripts, I made them modular similar to the post above, for example my tutorial island, blue Dragon, blast furnace,.. scripts all require either a main script class, or a 'proxy' class that allows me to use them separately or together in a script. The proxy class just makes sure all the onMessage, onPaint and onResponseCode gets forwarded to the correct module Edited January 10, 2017 by Abuse Quote Link to comment Share on other sites More sharing options...
Explv Posted January 10, 2017 Share Posted January 10, 2017 (edited) Hi, I am new to this API and bot scripting in general (not to coding though) and I'm unsure of how to accomplish using multiple scripts. I'm trying to use something like a "main" Script as an overarching entry point, which can call other Scripts in sequential order. This way, I could implement modular Scripts. So in my "main" script I have this: @[member='Override'] public int onLoop() throws InterruptedException { Script tinCopperMiner = new TinCopperMiner(); // TinCopperMiner is a local script Bot bot = this.getBot(); bot.getScriptExecutor().prepare(tinCopperMiner); bot.getScriptExecutor().start(tinCopperMiner); // call more local scripts as needed this.stop(); return 0; } The inner, modular Scripts would be responsible for calling stop(). This doesn't seem to work though (null pointer exception), probably am misusing the API... If you just want to execute a script after another has stopped you can use my manager: http://osbot.org/forum/topic/100554-explvs-osbot-manager/ But if you need something more complex, you could try initialising a script like so (I have not tested this): // Initialise the script Script someOtherScript = new SomeScript(); someOtherScript.exchangeContext(getBot()); // Call onStart someOtherScript.onStart(); // In onLoop of your wrapper script call return someOtherScript.onLoop(); You would probably also need to override the stop() method of the script you are running, so that it doesn't stop the ScriptExecutor and does something else instead. Edited January 10, 2017 by Explv Quote Link to comment Share on other sites More sharing options...
PineappleSausage Posted January 10, 2017 Author Share Posted January 10, 2017 Ah, thanks. Your tool looks great. Quote Link to comment Share on other sites More sharing options...