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
  • Stopping script within TaskNode


    Sicilian7

    Recommended Posts

    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

    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

    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

    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

    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

    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.