Commands vs Functions in Ubot Studio 

 July 23, 2021

By  Reed

Commands and functions are a core part of Ubot Studio. They are the building blocks that make up a bot. They are also an important foundational concept in programming, and since tools like Ubot are built off these concepts they are a foundational part of the bot building process.

As a bot builder you will eventually have to learn these concepts, so today we are going to show you just what commands and functions are and how they differ from one another. This will help clarify the bot building process.

In Ubot Studio commands and functions are available as drag and drop nodes that can be added to the Node view panel in Ubot Studio. There are different types of commands and functions available such as Flow commands, Browser commands, Log commands… which are all available in the Bot Bank panel available via the Wrench icon.

You will see that the Bot Bank panel has a tree view of different commands under different categories. The categories are designed to better organize commands so you can remember where they are. It’s not totally necessary to remember what each command is categorized under, but it is helpful in the beginning as you are exploring commands and functions. Most experienced ubotters rely on the search toolbox to find the commands and functions they need, and once you are comfortable you will too.

Commands

Commands perform actions. In Ubot Studio they are the blue nodes that are dragged into the Node view panel. In fact, commands are the only nodes that can be added to that panel itself.

Commands that are run will perform a task. A simple example of this is the navigate command below.

 navigate("sourceultra.com","Wait")

You can see the syntax of a command in the Code View panel. You will see that it often looks like this command(). This is common syntax in programming and whenever paragraphs are used it often indicates the command can accept input. This input can be user defined, meaning you add the value yourself like the example below.

set(#variable,"Something","Global")

In this example I have entered Something as the value of the variable. When the command runs that input is set as the variables value. If a command does not accept input the parenthesis will be totally empty.

Functions

Functions return data. They accept user input and other functions. They are the green nodes that start with a $, and they are available in the Bot Bank under the Parameters tree.  They are categorized as parameters because they are added to commands as input, like this example below.

set(#Example,$surround text("Something","\""),"Global")

In this example we are using a function to add quotes around user input. This input is returned as “Something”. The command performs the action of setting a variable, and the function has returned the data used to set it.

In the syntax we can see the $surround text function is inside the set() command’s parenthesis. You can also see that the $surrount text function also has it’s own parenthesis. This is because it too accepts user input. In order for it to return data it must itself have data, which in this case is user input.

In Ubot Studio there are functions like $nothing that do not require user input as they already are set to  value. When the $nothing function is added to a set() variable the variable will have no value because $nothing is set to equal nothing.

Pre-set functions save time when you have a lot of places in your script to use a specific value. You can create your own pre-set functions like $nothing by using the Define command. 

Define Custom Commands and Functions

The Define command is classified as a Flow command. It allows you to create your own custom commands and functions. When you create a custom command it becomes available as a usable command under the Custom Commands category in the Bot Bank, whereas custom functions are found in the Custom Functions category under the Parameters tree.

Visit("https://sourceultra.com")
define Visit(#URL) {
    navigate(#URL,"Wait")
}

This example is a custom command that accepts input and visits that input.  Below is a function that is set to the https://sourceutlra.com URL, which we can then use anywhere in our bot like. Here it is used in the custom Visit command.

Visit($SourceUltra())
define $SourceUltra {
    return("https://sourceultra.com")
}

By creating a custom function set to the URL I want to visit, we have basically made a reusable parameter that can be used anywhere in this bot where I need to use the URL. This can save time if you are using the same parameter multiple places.

You will notice that this custom function has a return command in it. This is because functions return data, which in this case is the https://sourceultra.com URL. 

You can set your functions to accept user input by adding a variable to the function. 

Visit($SourceUltra("https://sourceultra.com"))
define $SourceUltra(#Variabe) {
    return(#Variable)
}

The return now contains the variable. Our custom function can now take user input, and whatever we put in the variable will now be the value of the $SourceUltra() function. 


Reed

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Subscribe to our newsletter now!

RSS
Follow by Email
YouTube
X

Forgot Password?

Join Us