Jump to content
UBot Underground

How To Stop Script When Running With UI Button?


Recommended Posts

Hi guys. I'm currently moving over to using UI Buttons to run my bot. I was wondering if there's any way to stop my bot once it has started running with a UI button?
 
 
I tried attaching a stop script to a Stop UI Button, but it doesn't seem to work...

 

Link to post
Share on other sites

2 simple examples:

 

Example nr. 1:

ui stat monitor("Generate random numbers", #generaterandomnumbers)
comment("---generating random numbers until press <Stop Script> button ------")
ui button("Run") {
    set(#stop, $false, "Global")
    set(#i, 0, "Global")
    loop while($comparison(#stop, "!=", $true)) {
        set(#generaterandomnumbers, $rand(0, 100000), "Global")
        increment(#i)
    }
}
ui button("Stop Script") {
    set(#stop, $true, "Global")
}

Example nr. 2:

ui stat monitor("Generate random numbers", #generaterandomnumbers)
ui stat monitor("Generate random numbers", #generaterandomletters)
comment("---generating random numbers and words until press <Stop Script> button ------")
ui button("Run") {
    set(#stop, $false, "Global")
    set(#i, 0, "Global")
    loop($rand(25, 50)) {
        if($comparison(#stop, "=", $true)) {
            then {
                stop script
            }
            else {
            }
        }
        set(#generaterandomnumbers, $rand(0, 100000), "Global")
        set(#generaterandomletters, $random text($rand(3, 5)), "Global")
        increment(#i)
        wait(1)
    }
}
ui button("Stop Script") {
    set(#stop, $true, "Global")
}
  • Like 1
Link to post
Share on other sites

I've been going through this, and it seems that the only way at the moment is to set a variable between true and false, within a loop statement, with the stop button changing the variable to false to stop the script.... Am I correct?

 

This seems to work for shorter scripts. But what if I wanted my UI button to run a very long process? It would only be able to stop once the program loops at least once I guess... I can't stop it half-way, like the UBot Stop Button does... Unless maybe I put statements throughout the code, which is a bit troublesome.

 

Are there any other ways around this? Else I guess I'd better go back to using the Run and Stop buttons instead of the UI Button... :P

Link to post
Share on other sites
  • 2 weeks later...

I've been going through this, and it seems that the only way at the moment is to set a variable between true and false, within a loop statement, with the stop button changing the variable to false to stop the script.... Am I correct?

 

This seems to work for shorter scripts. But what if I wanted my UI button to run a very long process? It would only be able to stop once the program loops at least once I guess... I can't stop it half-way, like the UBot Stop Button does... Unless maybe I put statements throughout the code, which is a bit troublesome.

 

Are there any other ways around this? Else I guess I'd better go back to using the Run and Stop buttons instead of the UI Button... :P

 

I wanted to also reply to this thread.

 

Sorry guys, but these examples posted here are not right. By using an if statement from inside of a loop will only cause your bot to stop once it loops back around. Not really the ideal way to stop a bot using a UI button.

 

What I think that you are missing is you need to run a loop while inside of a thread at the top of your start button. That way whenever the variable changes from true to false it will stop your script the moment the button is clicked.

 

Check my post here for the example.

 

http://www.ubotstudio.com/forum/index.php?/topic/14767-an-easier-way-to-stop-script-when-using-the-ui-button/&do=findComment&comment=83501

  • Like 1
Link to post
Share on other sites

I wanted to also reply to this thread.

 

Sorry guys, but these examples posted here are not right. By using an if statement from inside of a loop will only cause your bot to stop once it loops back around. Not really the ideal way to stop a bot using a UI button.

 

What I think that you are missing is you need to run a loop while inside of a thread at the top of your start button. That way whenever the variable changes from true to false it will stop your script the moment the button is clicked.

 

Check my post here for the example.

 

http://www.ubotstudio.com/forum/index.php?/topic/14767-an-easier-way-to-stop-script-when-using-the-ui-button/&do=findComment&comment=83501

 

Thanks a lot Gogetta. I will check it out now. I was wondering why it was so difficult to do. :)

 

I'll look at your example.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...