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
  • Never put a loop inside your TaskNode or onLoop() method. Here's why


    century

    Recommended Posts

    Low effort post warning. I found myself extremely frustrated this evening, tussling with trying to stop a TaskNode mid-execution. I assumed it was continuing due to Thread management, which isn't the case and which you'll see me realize in the following chat log. In my drunken, half conscious state of inadequacy, I find myself without the mental power to summarize my learnings. So here's a chat log with Neffarion (you're awesome dude, thanks so much for the help).

     

    me - Today at 10:00 PM
    I was hoping that you'd be able to help me with a Thread stopping issue. When the red button is clicked, it seems to be waiting for all of the spawned threads to finished executing before calling onExit(). This causes issues because if the spawned thread contains a large task (like dropping your whole inventory), then it will finish the task before exiting. I was wondering if you could help me interrupt the thread as soon as the red button is clicked?   Warm Regards,   Matt
    Neffarion - Today at 10:03 PM
    You shouldnt do large tasks on other threads. You do that on the OnLoop.
    me - Today at 10:03 PM
    Well I'm not making an AbstractScript. I'm doing a TaskScript, which doesn't use onLoop()
    Neffarion - Today at 10:04 PM
    Well then do the tasks on the task nodes
    me - Today at 10:05 PM
    That's the idea. I just need some way of recognizing that the red button has been clicked so that I can stop the process
    Neffarion - Today at 10:06 PM
    Theres only the onExit
    me - Today at 10:06 PM
    Which is called after the TaskNode finishes
    Neffarion - Today at 10:06 PM
    yea
    me - Today at 10:06 PM
    I'm going to have to do some fuckery to pull this off
    Neffarion - Today at 10:07 PM
    taskscript is just abstractscript that loops trought tasknodes
    like I said, dont do inventory actions on other threads
    its messy
    me - Today at 10:08 PM
    when execute() is called, it spawns a thread, right?
    Or do I not understand the process at all
    Neffarion - Today at 10:08 PM
    what? no
    execute is called when the accept returns true
    no threads are created
    just 1
    doing all that
    me - Today at 10:09 PM
    are all of the TaskNodes on the same Thread?
    Neffarion - Today at 10:09 PM
    yes, they run on same
    me - Today at 10:10 PM
    so TaskNode objects don't implement Runnable?
    Neffarion - Today at 10:10 PM
    no
    me - Today at 10:11 PM
    How would you stop a TaskNode mid execution? If the red button is clicked?
    Neffarion - Today at 10:11 PM
    you dont, when red button is pressed it will always loop one last time per say
    me - Today at 10:12 PM
    So should I have one task node for each item drop?
    I just want to stop dropping when the button is clicked
    Neffarion - Today at 10:13 PM
    if u using a for or while loop inside the tasknode then u cant really do anything about that
    me - Today at 10:13 PM
    I mean
    If the Instance had some identifiable variable like redButtonWasClicked()
    I could just add that to the condition of my for loop
    Neffarion - Today at 10:15 PM
    there isnt any redbuttonwasclicked
    you can try to mess around getClient().getInstance().getScriptManager()
    me - Today at 10:16 PM
    oh shit
    indeed, i can.
    If I can't resolve viaScriptManager, I'm going to decompile org.dreambot.core and fire an event when the redbutton is clicked
    Neffarion - Today at 10:17 PM
    its obfuscated tough
    but if you cant trought the script manager you should just do 1 item per loop.(edited)
    me - Today at 10:19 PM
    Gonna need to re-write half my script
    But that's part of the fun, isn't it
    Lesson learned: no loops in your task node
    Neffarion - Today at 10:20 PM
    eh depends on what you are doing.
    if it is that important that it stops then yea, otherwise just let it finish
    me - Today at 10:21 PM
    To be honest, it's not important at all.
    I just want it to be perfect
    Neffarion - Today at 10:21 PM
    bc the way taskscript works, is that it checks all nodes accept and it goes trought priorities
    so u gonna get more cpu usage
    me - Today at 10:23 PM
    well my accept methods are pretty minimal
    a handful of statements max
    Neffarion - Today at 10:23 PM
    y but if u gonna lets say do something to 20 items it gonna loop trought the accepts 20 times
    me - Today at 10:24 PM
    do you have a metric for that? What's the relationship between eval statements and CPU usage?
    Like 500 evals = 10 cpus? I don't even know
    Neffarion - Today at 10:25 PM
    dont have any metrics
    it depends on your accept checks
    me - Today at 10:25 PM
    At the end of the day. Complexity is a small price to pay for function
    I was hoping I could just interrupt the process
    Would you be okay if I posed this conversation to the forum? I think it'd be helpful documentation for future devs
    Neffarion - Today at 10:27 PM
    you could try using getClient().getInstance().getScriptManager().getCurrentThread().interrupt()
    and getClient().getInstance().getScriptManager().getCurrentThread().isInterrupted();
    yea you can post stuff there
    me - Today at 10:32 PM
    Thanks for the help.
    And thanks for the motherlode miner :smiley:
    NEW MESSAGES
    Neffarion - Today at 10:33 PM
    oh np :]

     

     

     

    Link to comment
    Share on other sites

    • 3 months later...

     

    Low effort post warning. I found myself extremely frustrated this evening, tussling with trying to stop a TaskNode mid-execution. I assumed it was continuing due to Thread management, which isn't the case and which you'll see me realize in the following chat log. In my drunken, half conscious state of inadequacy, I find myself without the mental power to summarize my learnings. So here's a chat log with Neffarion (you're awesome dude, thanks so much for the help).

     

     

     

    Very helpful, I had to figure this out on my own and now looking up a separate issue I found this. I ended up making my own stop button in my script, that called thread.interrupt() on my main TaskManager

    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.