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
  • What happens when you click the red button to stop a script?


    TheAppFoundry

    Recommended Posts

    Hey guys, say for example I'm doing depositAllExcept() blah blah blah. While it's depositing those items I stop the script manually. (The red button)

     

    http://imgur.com/39OEIQ9 (Just a picture of the red button)

     

     

    I'm trying to figure out if there's a way to stop the script immediately after that method call.

     

    It doesn't throw anything and the Thread isn't being interrupted so it continues to execute the rest of the script. Interestingly enough, when I use dreambots sleep() method for like 3 seconds and check afterwards if the Thread was interrupted, it shows that it is. but not if you stop the script while your executing a function like deposit all except.

     

     

    This is some sample code:

            try {
                if (getInventory().contains(Constants.COINS) || getInventory().contains(Constants.ONIONS)) {
                    getBank().depositAllExcept(Constants.COINS, Constants.ONIONS); // deposit all except Onions and Gold
                } else
                    getBank().depositAllItems();
            }catch(Exception e){ log("Exception was caught");}
            if(Thread.interrupted()){
                log("Thread was interrupted in bank");
                throw new InterruptedException(); // Stop script if user wants to stop script
            }
            log("After");
    

    The exception does not get caught, and Thread.interrupted() returns false
    The log statement After gets executed along with the rest of the script.

     

     

    Note when you use Dreambot's sleep it gets executed:
     

            while(!Thread.interrupted()){
                log("interrupted");
                sleep(3000);
            }
    

    Lastly, if you do the native Thread.sleep(); and surround in a try and catch, an interrupted exception will be thrown.

     

    Link to comment
    Share on other sites

    You have to manually stop your Thread in onExit, any additional Thread you start is not handled by the ScriptManager and will persist to run until you close the Client or the Thread is terminated

    Link to comment
    Share on other sites

    You have to manually stop your Thread in onExit, any additional Thread you start is not handled by the ScriptManager and will persist to run until you close the Client or the Thread is terminated

    So you are saying that the main Thread is interrupted but the rest are not? If this is so, why is it not going into if(Thread.interrupted()) block.

    I still don't know what it does when you click it.

    Link to comment
    Share on other sites

    • 1 month later...

    You have to manually stop your Thread in onExit, any additional Thread you start is not handled by the ScriptManager and will persist to run until you close the Client or the Thread is terminated

     

    I'd like to revive this thread if possible. I'm noticing that onExit() is called only after the current TaskNode finishes. How can I recognize when the red button is clicked, and interrupt my Threads at that point?

     

    edit (Credit to TheAppFoundry). Use this in your condition to check if the Red Button has been cilcked:

    getClient().getInstance().getScriptManager().isRunning()
    
    Link to comment
    Share on other sites

    • 4 months later...

    The other option is to design your code so that tasks that do multiple things perform one each time it goes through the TaskNode. For example, a combat Task would look for a suitable enemy and click, then update its state to fighting and then exit. The next time the task is 'accepted' it would now be in the fighting state and do the next task then update to 'looting' state and exit. 

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • 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.