420x69x420 72 Share Posted May 18, 2022 I make lots of little changes to my code and would just like to apply them and see the effect immediately until it's satisfactory then broadcast these changes to multiple clients running. Usually I have to manually click each client's restart button to update them but I would like to just write a command in a text file to update all of them. I think if the script checks for this command every loop and then when it sees it, restarts the currently running script, it would be a good way. I know there is a script on the SDN that can start/stop other scripts in a supervisory way so I was wondering if I need to create a launcher script that stays running and will automatically restart the actual script when the command is present? Link to comment Share on other sites More sharing options...
Robosoldier2 2 Share Posted May 20, 2022 (edited) There are run() and stop() methods within AbstractScript class. I don't think these will help you load a new artifact though. https://dreambot.org/javadocs/org/dreambot/api/script/AbstractScript.html You could instead aim to automate the loading of the jar from outside the script. Below is a high level example: Have your Java detect when a new jar file has appeared on the system through a check on the modified date for example. If found, call stop(). Then a shell script either spawned by Java or acting independently could terminate all Dreambot processes at OS level, followed by spawning new processes with CLI arguments specifying the accounts and new jar file.. Someone more versed with Dreambot behaviour can sanity check my CLI thinking. I think it has that functionality, but at work so can't check. Edited May 20, 2022 by Robosoldier2 Link to comment Share on other sites More sharing options...
420x69x420 72 Author Share Posted May 24, 2022 Thanks, yes I can restart all clients with a built-in call in my script to system.exit(0) so I can write in the text file the command to system.exit(0) and all the clients will close, then I can re-launch all of them. But I was mostly wanting to restart the script rather than re-launch all clients because it's much faster that way. I know Bun's Automation Tool does it in it's own script (Bun's Automation Tool is the script you run on the DB client, then that script loads / runs another specified script and when that script is detected to be stopped, the Bun's Automation Tool script kicks back in and is able to load more again etc): Quote Script Queueing Scripts can be run under specific conditions, and stopped when certain goals are met or a certain amount of time has elapsed. @Bunnybun pls open source just these calls thx :D Link to comment Share on other sites More sharing options...
420x69x420 72 Author Share Posted May 30, 2022 I mean, there is a ScriptManager class that is in the API with stop(), run(), pause(), resume(), but I am failing to properly implement it somehow 😞 https://dreambot.org/javadocs/org/dreambot/api/script/ScriptManager.html Should I grab Instance.getInstance().getScriptManager() to actually see that class in effect? Or ScriptManager.getScriptManager() ? Do I have to run this code in the Main class of my .jar project (the script files)? In a static way??? etc Link to comment Share on other sites More sharing options...
camelCase 226 Share Posted May 31, 2022 11 hours ago, 420x69x420 said: Should I grab Instance.getInstance().getScriptManager() to actually see that class in effect? Or ScriptManager.getScriptManager() ? Do I have to run this code in the Main class of my .jar project (the script files)? In a static way??? etc to get an instance of ScriptManager you would ScriptManager manager = ScriptManager.getManager() once you use ScriptManager#stop the script will stop and wont execute ScriptManager#start, if you do it in the other order you wont be able to start a script because your current script is still running, for this reason you have to make a new thread to start a different script. heres what i do public class ScriptStarter implements Runnable{ @Override public void run() { ScriptManager manager = ScriptManager.getScriptManager(); manager.stop(); try { Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } manager.start("cCCannonballs", null); } } and then in my script when i wanted to change script i do ScriptStarter scriptStarter = new ScriptStarter(); log("trying to start cCCannonballs"); Thread t1 = new Thread(scriptStarter); t1.start(); Link to comment Share on other sites More sharing options...
420x69x420 72 Author Share Posted May 31, 2022 (edited) Aces mate! Thanks so much because that's exactly what I was looking to do! Edit: And also, you want to tell the initial script to exit prior to the thread sleep ending. For example return -1 in the Main onLoop() function of the initial script immediately after starting the new thread so the script is stopped before another one is started by the still-running thread. Edited June 5, 2022 by 420x69x420 camelCase 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now