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
  • TaskScript still checks accept() method of lower priority TaskNode, after accepting a higher priority TaskNode


    wefwefwef222

    Recommended Posts

    This is just a minor performance issue...

    My code:

    package bots.test;
    
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.impl.TaskScript;
    
    @ScriptManifest(category = Category.CONSTRUCTION, name = "AAAAAAAAAAAAAA", author = "me", version = 1.0)
    public class Test extends TaskScript {
        @Override
        public void onStart() {
            addNodes(new TestTask2(), new TestTask1());
        }
    }

     

    package bots.test;
    
    import org.dreambot.api.script.TaskNode;
    
    public class TestTask1 extends TaskNode {
        @Override
        public int priority() {
            return 1;
        }
    
        @Override
        public boolean accept() {
            log("task 1 accept");
            return true;
        }
    
        @Override
        public int execute() {
            return 5000;
        }
    }

     

    package bots.test;
    
    import org.dreambot.api.script.TaskNode;
    
    public class TestTask2 extends TaskNode {
        @Override
        public int priority() {
            return 2;
        }
    
        @Override
        public boolean accept() {
            log("task 2 accept");
            return true;
        }
    
        @Override
        public int execute() {
            return 5000;
        }
    }

    The subsequent logs:

    • 5:47:42 PM: [SCRIPT] task 2 accept
    • 5:47:42 PM: [SCRIPT] task 1 accept

     

    I don't believe that the loop() method for TaskScript should still be checking the accept() methods of lower-priority-than-already-accepted TaskNodes. For example, because TestTask2 has a priority of 2, and was accepted, the accept() method of a test task with a lower priority (in this example TestTask1) shouldn't even be executed, because it's not a priority. This will save some CPU usage, since integer comparisons are easy, but someone could have complex accept() code. Hopefully I'm making sense. Thanks!

    Link to comment
    Share on other sites

    Unfortunately this is necessary as the priority method isn't a constant, so we couldn't presort the tasks to exit on the first available task :(

    The performance implications of this design are minor, and if this is really a concern you're free to extend AbstractScript and create your own task based implementation :)

    Link to comment
    Share on other sites

    1 hour ago, Pandemic said:

    Unfortunately this is necessary as the priority method isn't a constant, so we couldn't presort the tasks to exit on the first available task :(

    The performance implications of this design are minor, and if this is really a concern you're free to extend AbstractScript and create your own task based implementation :)

    I'm not saying exit on the first accepted. I'm saying some logic like this (obviously I'm sure the logic behind the scenes is a little more complex):

        ArrayList<TaskNode> nodeList = new ArrayList<>(); // Populated on start...
        public void onLoop() {
            TaskNode bestAccepted = null;
            for (TaskNode taskNode : nodeList) {
                if (bestAccepted == null || (taskNode.priority() > bestAccepted.priority() && taskNode.accept())) {
                    bestAccepted = taskNode;
                }
            }
            sleep(bestAccepted.execute());
        }

    Idk, just a thought... and I get what you're saying about me writing my own, but using the DB built-in library classes is so convenient/clean I figured I would bring it up. The logic above would be checking if it's even worth it to check the .accept() method at all, saving some (sure, minor) CPU time.

    Link to comment
    Share on other sites

    1 hour ago, wefwefwef222 said:

    I'm not saying exit on the first accepted. I'm saying some logic like this (obviously I'm sure the logic behind the scenes is a little more complex):

        ArrayList<TaskNode> nodeList = new ArrayList<>(); // Populated on start...
        public void onLoop() {
            TaskNode bestAccepted = null;
            for (TaskNode taskNode : nodeList) {
                if (bestAccepted == null || (taskNode.priority() > bestAccepted.priority() && taskNode.accept())) {
                    bestAccepted = taskNode;
                }
            }
            sleep(bestAccepted.execute());
        }

    Idk, just a thought... and I get what you're saying about me writing my own, but using the DB built-in library classes is so convenient/clean I figured I would bring it up. The logic above would be checking if it's even worth it to check the .accept() method at all, saving some (sure, minor) CPU time.

    Oh alright I misunderstood, I'll take a look at our implementation and see if that's something I can fix up easily :)

    Ended up rewriting it, it should work as you've described starting in the next client release, thanks for pointing out the bug.

    Link to comment
    Share on other sites

    18 hours ago, Pandemic said:

    Oh alright I misunderstood, I'll take a look at our implementation and see if that's something I can fix up easily :)

    Ended up rewriting it, it should work as you've described starting in the next client release, thanks for pointing out the bug.

    Nice, thanks!

    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.