aidanm96 1 Posted October 22, 2023 When I click the square to stop my script it continues doing all of the actions of the current loop before finally stopping. How do I get it to stop everything as soon as the stop square is pressed on dreambot?
Slezzzy 21 Posted October 22, 2023 If a scripter has code that executes when a script is stopped then itll do that besides that what script?
sloppybot 18 Posted October 22, 2023 (edited) There's an issue where the script continues to run in the background if it's in a loop or recursive function call. If it's your script you can make a check for the loop or method condition to stop if the script has been stopped by user. public static boolean isScriptRunning() { return ScriptManager.getScriptManager().getState() == ScriptManager.State.RUNNING; } // Sleeps until script isn't running or your condition is true. Sleep.sleepUntil(() -> !isScriptRunning() || --Other condition you are running --, () -> --condittion that causes infinite loop on script stop--, 1000, 100); while (isScriptRunning() && -- Other Condition --) { // True as long as your condition is true and script is running. } public void recursiveMethod() { if (!isScriptRunning()) return; // Ends the recursive calls. recursiveMethod(); } https://dreambot.org/javadocs/index.html?org/dreambot/api/data/GameState.html Edited October 22, 2023 by sloppybot
Dexter Bots 35 Posted December 24, 2023 To stop a while loop, you need to have a condition within the loop that can become false. This condition is checked during each iteration of the loop, and when it evaluates to false, the loop stops. Here's a general explanation: Initialization: Start by initializing a variable that controls the loop, often referred to as a loop condition. While Loop: Use a while loop and set the condition to check whether the loop should continue. Actions: Perform the necessary actions or operations inside the loop. Exit Condition: Include an exit condition within the loop. When this condition becomes true, the loop will exit. Updating the Condition: When the exit condition is met, update the loop control variable to make the condition false. Delay (Optional): To prevent the loop from running too quickly and causing performance issues, you might want to include a short delay between iterations. This way, the loop will run until the exit condition is satisfied, providing a controlled and intentional termination point for the loop.
apnasus 58 Posted January 1, 2024 (edited) On 10/22/2023 at 8:49 AM, aidanm96 said: When I click the square to stop my script it continues doing all of the actions of the current loop before finally stopping. How do I get it to stop everything as soon as the stop square is pressed on dreambot? Honestly, I would recommend writing shorter loops that return more often, but if you really want to achieve the above, then you could listen for mouse clicks in the stop button region, have the mouse click flip a Boolean, and use that Boolean as a return condition for every single statement in your loop. That way the loop will pretty much as soon as you hit stop. Edit: you can use GameState per the above if it changes as soon as you hit stop, as I'm pretty sure it does, and not when the loop ends Edited January 1, 2024 by apnasus
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