Objective
The objective of this How-To guide is to demonstrate the use of iterative variables in OpenBots Studio. Iterative variables keep track of the number of times a certain action has occurred. They are most often used with other commands such as loops and if statements.
Walkthrough
The following are the steps involved in implementing basic variable functions.
Step 1:Use the Set Variable Command to give a newly created variable an initial value.
  • Select Set Variable Command
  • Define input to be set to the above variable: 5
  • Create a new variable in the ‘Output Variable’ parameter by using the Ctrl+K hotkey to navigate to the Variables Manager window (created variable called vCount in this example)
  • Click OK
Step 2:After creating the variable, use the ‘Do While’ command to start a loop a given number of times
  • Select Do While Command
  • Condition Option: Builder
  • Do While Condition: Number Compare
  • Number1: vCount
  • Operand: is greater than
  • Number2: 0
  • Basically, the user is creating a loop to run a series of code as long the value of {vCount} is greater than 0./li>
  • Click OK
Step 3: Use a Show Message Command to display the count. This command must be placed inside the loop
  • Select Show Message Command
  • Write the following for ‘Message’: “The current count is” + vCount + “!”. The variable will change value for every iteration of the loop, starting at 5 and ending at 1.
  • Select the duration of the window (optional)
  • Click OK
Step 4: Use the Set Variable Command to subtract 1 from the value of vCount. This value must be placed inside the loop to change the value for the next iteration of the loop
  • Select Set Variable Command
  • For the Input value, type in this: vCount – 1. This will reduce the value of the variable by one
  • Write in vCount for the Output Variable. Exactly what is happening here the user is changing the original value of vCount from 5 to 4, then 4 to 3, etc. for each iteration of the loop. Then, in the next iteration of the loop, show message command will display the new value for the count (please see the images at the end of this guide)
  • Click OK
When the user runs the script, this message window will appear:
From here, the value of vCount is reduced by 1 and becomes 4. The loop then resets and start its second iteration by showing the message window with the new value:

After that, the value will then be reduced by 1 and the loop will re-start again. The loop will continue to run if the value of vCount is greater than 0. This is the condition of the loop we wrote back in step 2. When vCount reaches 0, the loop ends.

All the commands in this guide can be utilized alongside many of the other commands that will be discussed in later guides to perform several operations. Below is a snapshot of the process discussed in the guide.

Commands utilized for the above concepts (Using iterative variable in OpenBots Studio) are as follows:

Variable Commands: Set Variable

Loop Commands: Do While

Newsletter Bot

Lets stay in touch!

Join our weekly newsletter and follow us on social media.

Contact Sales
Call Our Experts!