TheAppFoundry 11 Share Posted July 24, 2017 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 falseThe 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 More sharing options...
Dinh 496 Share Posted July 24, 2017 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 More sharing options...
TheAppFoundry 11 Author Share Posted July 26, 2017 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 More sharing options...
century 26 Share Posted September 2, 2017 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 More sharing options...
Zaveix 0 Share Posted January 14, 2018 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.