JGhost Posted February 24, 2016 Share Posted February 24, 2016 (edited) I'm trying to run a script using the scriptExecutor but i'm not sure if i'm using the API correctly. package scriptDispatcher; import scripts.CookingAssistantScript; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.event.ScriptExecutor; import java.awt.*; @ScriptManifest(author = "JGhost", info = "Script Dispatcher", name = "Script Dispatcher", version = 0, logo = "") public class main extends Script { ScriptExecutor mainExecutor; ScriptExecutor dispatcher = new ScriptExecutor(bot); Script mainScript; Script taskScript; @Override public void onStart() { log("Script Dispatcher Started"); mainExecutor = this.bot.getScriptExecutor(); mainScript = mainExecutor.getCurrent(); taskScript = new CookingAssistantScript(); } @Override public int onLoop() throws InterruptedException { try { if (!dispatcher.isRunning()){ dispatcher.start(taskScript); } else{ log("script is running!"); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return random(200, 300); } @Override public void onExit() { log(""); } @Override public void onPaint(Graphics2D g) { } } I'm trying to go from this: Bot -> MainScriptExecutor -> MainScript to this: Bot -> MainScriptExecutor -> MainScript -> SecondaryScriptExecutor -> SecondaryScript is this achievable through the API? Edited March 1, 2016 by JGhost Quote Link to comment Share on other sites More sharing options...
LoudPacks Posted February 24, 2016 Share Posted February 24, 2016 (edited) Lem0n API does this, you could check it out cause its open source and built off of the regular OSBot API. Edited February 24, 2016 by LoudPacks Quote Link to comment Share on other sites More sharing options...
JGhost Posted February 24, 2016 Author Share Posted February 24, 2016 Lem0n API does this, you could check it out cause its open source and built off of the regular OSBot API. Thanks for the reply, I'll definitely look into Lem0n. Though id still like to know if the scriptExecutor will allow me to pick and choose which script to run. Quote Link to comment Share on other sites More sharing options...
JGhost Posted February 24, 2016 Author Share Posted February 24, 2016 (edited) Lem0n API does this, you could check it out cause its open source and built off of the regular OSBot API. I fail to see how Lemon API relates to enabling OSBot to run multiple scripts. Can you elaborate? Edited March 1, 2016 by JGhost Quote Link to comment Share on other sites More sharing options...
FrostBug Posted February 24, 2016 Share Posted February 24, 2016 A few points to note: - You should probably stick to a single ScriptExecutor (the one provided by the Bot instance). I doubt two script executors can run for the same Bot instance. - You would need to control the ScriptExecutor asynchronously (outside the context of your main script). If the ScriptExecutor is not running, your onLoop will never be called again, and you won't be able to start up the next script. - Take a look at calling the 'prepare' method before 'start'. Be sure to terminate the previous script before attempting to run a new one. Not sure if this is even possible, but it's worth a shot :E Quote Link to comment Share on other sites More sharing options...
LoudPacks Posted February 24, 2016 Share Posted February 24, 2016 (edited) I fail to see how Lemon API relates to enabling OSBot to run multiple scripts. Can you elaborate? Main.java lets u add a TaskScript. In main you can add(new TaskOne()); In side of TaskOne you have isActive which makes that specific task active when it return true. It also contains the looped code for said task. With it, you can write several "Tasks" or scripts that can all be added to the queue and ran within the main.java. I usually separate different tasks within a single script into different taskscripts, but you could also use different taskscripts as different scripts. For example, TaskOne() onActive() returns true if if the bank contains less than 500 bows, and will cut logs into bows, TaskTwo() might return true if you have 500 + bows in the bank, and could be set to perform a different task, like begin alching the bows. In this case I guess you could say you have two different scripts all within the same script. One for fletching, one for alching. Main: public void onStart() { super.onStart(); Settings settings = new Settings(this); settings.setCallback(b -> { start = System.currentTimeMillis(); //addTask(new Task()); addTask(new EatTask()); addTask(new OpenBankTask()); addTask(new BankingTask()); addTask(new SpiritTreeTask()); addTask(new GrandTreeTask()); addTask(new LadderOneTask()); addTask(new DaeroTask()); addTask(new WaydarTask()); addTask(new LumboTask()); addTask(new WalkToDungTask()); addTask(new WalkToSpotTask()); addTask(new CombatTask()); }); } In this case, I have different tasks for different steps in my script. These could easily be replaced with completely unrelated tasks, allowing you to have multiple scripts in one. Example Task import lemons.api.tasks.templates.AbstractTask; public class Task extends AbstractTask { private final long startAmount; @Override public void onStart() { super.onStart(); } public void onTaskStart() { //setup code startAmount = getInventory().getAmount(995); } public void run() { //code is looped getInventory().interact(995, "Drop"); } @Override public void onTaskFinish() { } @Override public boolean isActive() { return (getInventory().contains(995)); } } Edited February 24, 2016 by LoudPacks 1 Quote Link to comment Share on other sites More sharing options...
JGhost Posted February 24, 2016 Author Share Posted February 24, 2016 (edited) A few points to note: - You should probably stick to a single ScriptExecutor (the one provided by the Bot instance). I doubt two script executors can run for the same Bot instance. - You would need to control the ScriptExecutor asynchronously (outside the context of your main script). If the ScriptExecutor is not running, your onLoop will never be called again, and you won't be able to start up the next script. - Take a look at calling the 'prepare' method before 'start'. Be sure to terminate the previous script before attempting to run a new one. Not sure if this is even possible, but it's worth a shot :E Thanks Frost!I did try using prepare before starting the script but i still received an error message. The API doesn't exactly say what prepare(Script script) does, but id assume it's necessary to call before attempting to start a script. FrostBug, on 24 Feb 2016 - 03:55 AM, said: I doubt two script executors can run for the same Bot instance. Sounds like that makes sense, although that would be unfortunate for me if that's really the case. I didn't know that the ScriptExecutor was limited to only handle 1 script per bot. FrostBug, on 24 Feb 2016 - 03:55 AM, said: - You would need to control the ScriptExecutor asynchronously (outside the context of your main script). I think that control of the ScriptExectuor is key to getting this idea of mine to work. The only problem is I don't understand how it works or what is the process/conditions it uses to run a script. It wasn't labeled "For internal use only" so I'm assuming it has some practical use. I've tried prepare(Script script) before start(Script script), but i kept getting an error. Does anyone know if it is possible create a new ScriptExecutor(Bot bot) in a seperate thread, use prepare(Script script) to set up a new script, then switch the currently running ScriptExectutor (this.bot.getScriptExecutor() in main) then switching it with the new ScriptExecutor? LoudPacks, on 24 Feb 2016 - 11:42 AM, said: In this case, I have different tasks for different steps in my script. These could easily be replaced with completely unrelated tasks, allowing you to have multiple scripts in one. Thanks for the explanation Loud! I'll definitely be giving this a try. Edited February 24, 2016 by JGhost Quote Link to comment Share on other sites More sharing options...