Custom Start Stop Buttons In Ubot Studio

Introduction

In this article we are going to look at how to use custom Start and Stop buttons in a UI HTML Panel. This is for those people who want to get rid of the Ubot Run Bar. Below I outline everything you need to know and provide a basic example at the end.

As always there is more than one way to do something but I personally like doing it this way. In the past I’ve used if then statements instead of the “Check Stop” custom command we will go over in this article. If you are multi-threading in some cases you may want to use an if then statement instead of the Check Stop command. But for now if you are new to this try out my way of using this “Check Stop” command.

Requirements

  • Ubot Studio Developer Edition
  • Basic HTML knowledge
  • Basic understanding of custom defines

Advantages And Disadvantages

Advantages

  • Makes your program look better
  • Freedom to name buttons whatever you want
  • Ability to have several buttons that start/stop several scripts

People want to get away from the Ubot look and in my experience this seems to be the main reason people want to use their own buttons.

Another advantage to learning this technique may not be so obvious. But in some cases you want to have buttons in your GUI which perform different actions. Sometimes these can be tasks which require many resources or take a long time and you can have a stop button to kill the task or a universal stop button to kill all tasks.

Disadvantages

  • More code needs to be written
  • Default Ubot buttons are built in and already done for you
  • Custom buttons may not stop your script immediately

The biggest disadvantage to using your own buttons is that the script will not be killed instantly; because the program will have to reach the “Check Stop” point which we will cover later.

Understand The Roles

In order to implement your own custom start stop buttons into your program you will need 3 different things. The start button, the stop button, and a custom command. Let’s take a look at each.

The Start Button

Inside of the start (custom) command there needs to be two vital things in order to make everything work. The first is an if then statement to see if the program is already running. You do not want to let the user have the ability to start the script over and over again by pressing the start button.

The second vital thing you need is a variable with the value of true or false. You need to use this variable with the if then statement above to make sure it works correctly.

The Stop Button

The stop button has a few objectives. The primary objective is of course to stop the program as fast as possible. But it may also have to do some other things.

Once the stop button has been pressed there may be time in-between the button being pressed and the program actually stopping. In a multi-threaded program you may have it setup to finish the current threads before stopping – which may take several seconds. The stop button must inform the user of what’s going on in these cases. It could pop an alert box letting the user know that the program is in the process of stopping or “waiting for threads to finish.” It may also update the user via a status message in the GUI itself.

Sometimes there are other threads running and doing other tasks such as updating a datagrid. These will be running while the program is running. When you hit the start button it will set a variable to be true. This variable will change to false when the stop button is pressed. These other threads can be in a loop while that variable = true. This is the last thing the stop button typically does.

The Check Stop Custom Command

This custom command can be named whatever you want but in this case we are going to call it Check Stop.

The objective of this command is to house the Stop Script command. The Stop Script command is used in an if then statement. We will put this all into a custom command in this case Check Stop.
The reason we do this is because we want to litter the program with this Check Stop command. And in the future if for some reason we need to add something in or change anything we only have to update it in one place. It also makes the code look much cleaner!

Putting It All Together

Before you copy these codes into your own programs there is one more important thing you cannot leave out. Before your script ends you must set #running back to false:

Otherwise, if they do not hit the stop button and the program ends #running will still be true and they will not be able to start the program up again.

Click Here To Download Basic Example

Happy Ubotting!

P.S. Check out my last blog post, I don’t blog often so when I do I try to make it valuable!

Leave a Reply