Sicilian7 9 Share Posted September 12, 2020 Is there a simple way to stop the script when I'm inside a TaskNode? stop() doesn't work since it's only defined for AbstractScript. Link to comment Share on other sites More sharing options...
Pseudo 179 Share Posted September 12, 2020 Returning -1 in parent class cycle works iirc. Link to comment Share on other sites More sharing options...
Sicilian7 9 Author Share Posted September 12, 2020 2 hours ago, Pseudo said: Returning -1 in parent class cycle works iirc. I'm kinda new to TaskScripts/TaskNodes. Can you elaborate? Link to comment Share on other sites More sharing options...
Xtra 31 Share Posted September 13, 2020 23 hours ago, Sicilian7 said: I'm kinda new to TaskScripts/TaskNodes. Can you elaborate? So at any time in the loop you can do: return -1; And it will stop the script Link to comment Share on other sites More sharing options...
LordJashin32 54 Share Posted September 14, 2020 Hmm, I've never tried @Xtra's response before. Your main loop, you can handle in multiple ways. I use a boolean to check if what I have inside my loop should play or not like so: private boolean playing; @Override public int onLoop() { if (playing) { // Do stuff } return 300; } I also use Client.getInstance().getScriptManager().stop(); sometimes. The key is to check for a boolean. And then do break; or whatever you need to do to kill the program. USE Dreambot 3 because it handles this a lot better. Link to comment Share on other sites More sharing options...
Sicilian7 9 Author Share Posted September 14, 2020 3 hours ago, LordJashin32 said: Hmm, I've never tried @Xtra's response before. Your main loop, you can handle in multiple ways. I use a boolean to check if what I have inside my loop should play or not like so: private boolean playing; @Override public int onLoop() { if (playing) { // Do stuff } return 300; } I also use Client.getInstance().getScriptManager().stop(); sometimes. The key is to check for a boolean. And then do break; or whatever you need to do to kill the program. USE Dreambot 3 because it handles this a lot better. onLoop is only defined for AbstractScript. There is no notion of it in TaskScript so I am not sure what your answer is supposed to address. Link to comment Share on other sites More sharing options...
LordJashin32 54 Share Posted September 15, 2020 3 hours ago, Sicilian7 said: onLoop is only defined for AbstractScript. There is no notion of it in TaskScript so I am not sure what your answer is supposed to address. Well. I agree stop is only for db2. With db3 i don't need to use Client.scriptmanger etc stop. Umm. So here's how it works. Each node gets executed. Then ur loop is finished and u can return -1 and stop the script. OR u can check for a variable in each of your nodes whether or not to stop them before they are executed. Unless I'm totally wrong but TaskScript extends AbstractScript. They aren't totally different. And i read another post that says the return value is the amount of sleep for your loop. So return 300 is 300 sleep and return -1 stops the loop totally. Anyway so what you can do is create your own Node class or TaskNode class. And add a variable in there that is public that is like the "playing" thing u saw above where in each Nodes accept or execute functions u can check to see if the script is in the playing state with the variable. Link to comment Share on other sites More sharing options...
LordJashin32 54 Share Posted September 15, 2020 That's what makes OOP so crazy. You can pick your Poison. Do you want Injection to inject your main class into your task nodes and access their variables? Or do you want to completely Extend or Override your classes? Or do u wish to go completely procedural and smash the poison cup on the ground! E.g. import org.dreambot.api.script.TaskNode; public abstract class MyTaskNode extends TaskNode { public boolean playing; } public class WalkTask extends MyTaskNode { @Override public boolean accept() { if (!this.playing) log("HAHA we have stopped playing the script we have to abandon ship"); return false; } @Override public int execute() { return 0; } } etc Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.