Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Script not stopping


    aidanm96

    Recommended Posts

    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?

    Link to comment
    Share on other sites

    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 by sloppybot
    Link to comment
    Share on other sites

    • 2 months later...

    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:

    1. Initialization: Start by initializing a variable that controls the loop, often referred to as a loop condition.

    2. While Loop: Use a while loop and set the condition to check whether the loop should continue.

    3. Actions: Perform the necessary actions or operations inside the loop.

    4. Exit Condition: Include an exit condition within the loop. When this condition becomes true, the loop will exit.

    5. Updating the Condition: When the exit condition is met, update the loop control variable to make the condition false.

    6. 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.

    Link to comment
    Share on other sites

    • 2 weeks later...
    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 by apnasus
    Link to comment
    Share on other sites

    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 account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.