Skip to main content

Laiye BotScript Reference

A number of users prefer to use Laiye RPA's code view to write a process block. The code view uses BotScript (hereinafter referred as Laiye BotScript), a programming language created by Laiye RPA to describe process blocks. This chapter will provide a foundational knowledge of Laiye RPA code-view and Laiye BotScript.

This chapter is recommended for readers with a background in any of the common programming languages. To fully understand the information detailed in this chapter, it is crucial for the reader to be familiar with basic programming concepts including variables and functions. If you lack knowledge in this area, please read the previous chapter.


As mentioned previously, Laiye RPA was designed to be powerful, simple, and fast. Laiye RPA is aimed at both beginners, without any technical skills or expertise, who wish to quickly learn and automate simple processes; and also advanced developers who can rely on their existing computing knowledge to increase the efficiency of their operations through intelligent automation.

In order to meet the aims above, Laiye RPA provides a visual process interface for beginner-friendly programming experience, whole also offering a programming language that is simple, easy to learn and similar to common, everyday language to allow business professionals to understand and automate without any difficulties. The interface can be switched at any time during coding.

This chapter mainly introduces basic grammar rules of Laiye BotScript, which readers with programming knowledge can master within two hours. The time spent learning should be shorter for those who are already familiar with basics of the button wizard.

For Laiye RPA, the programming language is just a tool for expressing logic, and the key functions are still implemented by function libraries or plug-ins. Therefore, language design only includes basic logic. All specific functions, even the most basic "delay" functions, are excluded in the language design. However, they are designed separately in the function library. This chapter also does not include the introduction of the function library.

The Laiye BotScript is designed in a unique manner, rather than popular programming languages such as Python, JavaScript, and etc. It is because Laiye RPA is primarily aimed towards business professionals without advanced technical skills or programming knowledge. Laiye BotScript is designed to be as close to the vernacular as possible so as to facilitate easy learnability for those who are familiar with the English language.

In contrast, mainstream coding languages, while efficient, can be difficult for business professionals to learn adequately. JavaScript, for example, is a powerful coding language which- as an example, although JavaScript is a great language and can play a very high efficiency in the hands of professional programmers, even Laiye RPA itself has some codes written in JavaScript, the extensive use of parentheses in this language is easy to bring obstacles to the learning of non-professionals. As shown below:

**Figure 1: Complex JavaScript**

Therefore, we designed a special Laiye BotScript and made it as simple as possible, even using elements other than letters and numbers as few as possible. In fact, we have also considered the possibility of using popular programming languages on the market, because if we do so, our development workload will be greatly reduced. However, at the same time, user learning difficulty will be greatly increased.

Therefore, we rejected this idea and decided not to use popular programming languages such as Python.

However, Laiye BotScript includes many advantages of other programming languages. You will learn some characteristics of Visual Basic, Python and JavaScript language in the design of Laiye BotScript. The reason Laiye BotScript is simple, easy to learn and easy to use is because it draws on the strengths of others, absorbing the most easily understood and commonly used parts and deleting the complex and uncommon parts.

We believe that Laiye BotScript is currently the most suitable programming language in the RPA field.

Basic Structure

The source code file of Laiye BotScript is in plain text format with unlimited extension and UTF-8 encoding.

The source code of the Laiye BotScript is composed of multiple statements. Like general scripting languages such as Python and JavaScript, the Laiye BotScript does not have a set structure and explicitly specified entry. When a flow block is executed, it starts from the first line and the function definition is skipped temporarily, then it continues to execute from the line after the end of the function (for the concept of the function, please refer here).

In general, we recommend writing only one statement per line. If you must write multiple statements, please separate them with a colon separator (:).

If the content of a line is not enough and you need to break the line, you can use a comma (,) or a binary operator in any statement (please refer to the concept of "binary operator" here), and directly break the line without adding additional symbols. It is also not recommended to break in other places. But if you must break the line elsewhere, you can use a backslash () as the line break symbol. For example:

Dim a= \

When there is // in a line, it means that the content from then on is a comment. The content contained in /* */ is treated as a note no matter how many lines released.


// Here
is also
the comment

The comment has no effect in the process of running and is only for our convenience.

All keywords, variable names, and function names in Laiye BotScript are not case-sensitive. For example: the variable names abc, ABC or Abc are all considered to be the same variable.

Variables, Constants and Types of Data

Types of Data

Variables are the most basic functions in a programming language. Variables can store numbers, strings, and other values, as well as changing the values in the variables at any time during operation. Variables in Laiye BotScript are dynamic types, that is, the value and the type of variables can be dynamically changed during operation. This conforms to the conventions of general scripting languages such as Python and JavaScript. Variables can be divided into the following types: integer, floating point, Boolean, string, function, compound, and null type.

Integer values can be expressed in decimal or hexadecimal, where the hexadecimal is prefixed with &H or &h.

The value of a floating-point number can be expressed in a conventional way or in scientific notation. For example, 0.01,1E-2 or 1e-2 all represent the same floating number.

Boolean values are only True or False, neither of which is case-sensitive.

The string value is enclosed by a pair of single quotation marks (') or double quotation marks ("). You can use \t for tabs, \n for newlines, \' for single quotation marks, \" for double quotes, and \ for backslash itself. The newline can be directly wrapped in the middle of the string without adding any other symbols, and the newline will also be part of the string.

You can also use three single quotation marks (' ' ') before and after to represent a string, which is called a long string. In long strings, you can directly write carriage returns, single quotes, and double quotes without using \n, \', or \".

The value of the function type can only be a defined function, which will be described in detail later.

Complex values include arrays, dictionaries, and etc., which will be explained in detail in the next section.

Null values are always Null and are not case-sensitive.


a = 1        // a is a integer variable
a = &HFF // a is also a integer variable
a = True // a is a Boolean variable. As a dynamically typed language, the type of A can be changed from time to time
a = FALSE // a is a Boolean variable. Note that True and False are not case-sensitive
a = 'Laiye RPA' // a is a string variable
a = "Laiye RPA
RPA" // a is a string variable, and you can wrap a line in a string
a = null // A is a Null variable and can be written as Null, Null, or Null (not case-insensitive)

Variables and Constants

Variables are defined as:

Dim variable name

When defining the name of a variable, an initial value can be assigned to the variable:

Dim variable name = value

To define multiple variables, you can define them as follows:

Dim variable name 1 = value 1, variable name 2
Dim variable name 2 = value 2, variable name 2 = value 2

Constants are defined in a similar way to variables, except that Dim is changed to Const, and the value must be specified at the time of defining:

Const constant name = value, constant name = value

The only difference between a constant and a variable is that a constant can only be assigned a value once when it is defined, and it cannot be modified later.


Dim a // Define a variable named a, and no value assigned yet

Dim b = 1 // Define a variable named b and assign the value 1

Dim c, d = True // Define two variables named c and d, and assign True to d

Const e = 'Laiye RPA' // Define a constant named e and assign it the string 'Laiye RPA'

Const f // Error: constant must have initial assignment

For named things (such as variables, constants, functions, etc.), their names are collectively called identifiers, which need to be defined in accordance with certain rules.

Identifiers can be represented by English letters, underscores (_), and any characters other than English (including Chinese characters, of course) included in the encoding. In addition to the first character, you can also use numbers 0-9. Variable names are not case-sensitive.

The Laiye BotScript requires that variables must be defined before they can be used (except for loop variables in For statements, abnormal variables in Try statements, function parameters, etc.). When a variable is defined within the scope of a function, it is a local variable and is cleared when the function exits. When defined anywhere outside the scope of the function, it is a global variable and will not be cleared during operation. Global variables can be defined anywhere outside the scope of the function, without affecting their use, and can even be defined after the variables are used.

Compound Type

In addition to commonly used data types such as integers and strings, Laiye BotScript also includes two compound types: arrays and dictionaries, which are not different from ordinary variables in their definitions.

The values of the array can be written in this way:

[value 1, value 2, value 3]

The value can be of any type, and different values in the same array can also be various types. The value can even be another array, which constitutes a multidimensional array in the general sense.

The value of the dictionary can be initialized in this way:

{name 1: value 1, name 2: value 2, name 3: value 3}

The name can only be a string, while the value can be of any type. If you are familiar with JavaScript or JSON, you will find that this initialization method is highly similar to JSON representation.

Regardless of whether it is an array or a dictionary, please refer to the elements in it, and use square brackets as the index. If you want to refer to an array in the array (that is, the multidimensional array), or the array in the dictionary, you can continue to write new square brackets afterwards, such as:

Variable name [index 1][index 2]

The elements in the array or dictionary in this way can be used as l-values or r-values, that is, you can use the values or assign values to the contents, even add new values.


Dim variable = [486, 557, 256]  // Variables can be named in Chinese, and the initial value is an array
a = variable[1] // At this time a is assigned a value of 557
variable = {"key1":486, "key2":557, "key3":256} // Change the type of variable to a dictionary
a = variable ["key1"] // At this time a is assigned a value of 486
Variable ["key4"] = [235, 668] // Add a new value to the dictionary, which can be an array
//At this time, the content in the dictionary is {"key1":486, "key2":557, "key3":256, "key4":[235,668]}
a = variable ["key4"] [0] // At this time a is assigned a value of 235

Note: when referencing an element in an array or a dictionary, the index of the array can only be of integer type, with 0 as the starting index; the index of the dictionary can only be of string type. If it is not used correctly, errors will be reported at runtime.

Operators and Expressions

The operators and their meanings in Laiye BotScript are as follows:

Concatenation stringExponentiationLess thanLess than or equal to
Greater thanGreater than or equal toUnequalEqual/valuation
Logic ANDLogic ORLogic NotTake the Remainder

Linking variables, constants, and values together with operators and parentheses () is called an expression. Among the above operators, Not is a unary operator, it can be used as a unary operator or a binary operator, and all others are binary operators. The unary operator allows only one element (variable, constant, expression, or value) to appear on the right, and the binary operator allows only two elements to appear on both the left and right sides.

Note: when = appears inside the expression, it means to determine whether they are equal. When = forms an independent statement, the meaning is valuation. Although the design of = here is ambiguous, it can be better accepted by beginners.

In Laiye BotScript, some operators that are available but not commonly used in other languages are deleted, such as integer division operator, bitwise operator, etc. Because of this, these operators have fewer usage scenarios, and even if needed, they can be implemented in other ways.

Expressions are often used in valuation statements. You can assign values to a variable in the form:

Variable name = expression

Note that when the expression is an independent (not calculated using any operator) array or dictionary type variable, the assignment operation only assigns its reference, that is, just adds an "alias" to the variable. When the elements in an array or dictionary change, the other will also change.

For example:

a = [486,  557,  256]   // a is an array
b = a // b is the “alias” of a
b[1] = 558 // Change the value in b, the value in a will also change
c = a[1] // At this time the value of c is 558 instead of the original 557
a = 557 // At this time a is assigned a value of 557 (becomes an integer)
b = a // At this time, the value in b is also 557, but it is saved separately from a
b = 558 // The value in b changes, the value of a does not change
c = a // At this time, the value of c is still the original 557, because a is not a dictionary or array

Logical Statement

Conditional Branch Statement

The most common "If...Else" statements are used to judge one or more conditions to execute different processes. In Laiye BotScript, these are the following forms:

If condition
Statement block1
End If
If condition
Statement block1
Statement block2
End If
If condition 1
Statement block1
ElseIf condition 2
Statement block2
Statement block3
End If

If the condition is satisfied, the statement block after the condition will be executed; otherwise, the statement block will not be executed. The statement block after Else will be executed if none of the previous conditions are met.


// Time.Hour() can get the number of hours in the current time
// TracePrint() can output the specified content to the output column of Laiye RPA

If Time.Hour() > 18 // Get hours in current time
TracePrint("closing time")
Else // If it is greater than 18, then execute the statement here
TracePrint("business hours") // If the previous conditions are not met, execute the statement here
End If

Select Branch Statement

To select a branch statement, Laiye RPA will first evaluate the expression after "Select Case" and then determine if any of the Case branches agree with the value of the expression. If none of the expressions are satisfied, it will execute the statement block following the case "else".

Select Case expression
Case expression1, expression2
Statement block1
Case expression3, expression4
Statement block2
Case Else
Statement block3
End Select


Select Case Time. Month() // Get the month in the current time

Case 1,3,5,7,8,10,12 // If it is 1, 3, 5, 7, 8, 10, December

DayOfMonth = 31 // There are 31 days in the month

Case 4,6,9,11 // If it is April, June, September, or November

DayOfMonth = 30 // There are 30 days in the month

Case Else // If it is something else (that is, February)

DayOfMonth = 2 // There are 28 days in the month (not considering the leap year)

End Select

TracePrint (DayOfMonth)

Conditional Loop Statement

In the Laiye BotScript, the Do...while statement is used to implement a conditional loop; that is, while certain conditions are met, a certain statement block is executed in a loop. The Do...while loop statement can be used in the following five different forms in a flexible manner:

  1. The precondition is established and the loop is executed: the condition is judged first, and if the condition is established, the statement block is executed in a loop, otherwise the loop is automatically exited.
Do While condition
Statement block
  1. Loop if the precondition is not established: contrary to the previous one, exit the loop if the condition is true, otherwise the loop executes the statement block.
Do Until condition
Statement block
  1. Loop if the post-condition is established: the statement block is executed first, and then the condition is judged. If the condition is met, the statement block is continued to be executed, otherwise, the loop is automatically exited.
Statement block
Loop While condition
  1. Loop if the postcondition is not established: the statement block is executed first, and then the condition is judged. If the condition is met, the loop is automatically exited, otherwise, the loop continues to execute the statement block.
Statement block
Loop Until condition
  1. Infinite loop: The loop statement itself does not make any judgments, and it needs to make its own judgment in the statement block. If there is no statement that jumps out of the loop in the statement block, the loop will be executed indefinitely.
Statement block


Do Until Time. Hour() > 18 // Judge the number of hours in the current time, and loop as long as it is not greater than 18

TracePrint("It is not yet time to get off work") // Each time through the loop, the statement here is executed

Delay(1000) // For each judgment, take a one-second break


TracePrint("It is time to get off work") // If it is greater than 18, break out of the loop and execute the statement here

Count Loop Statement

The count loop statement is mainly used to execute a certain number of loops, and its basic form is:

For cyclic variable = [start value] To [end value] Step [step size]
Statement block

In the count loop statement, the start value, end value, and step size must be integers or floating points. If the step size is omitted, the default value is 1. The variable starts at the start value and is incremented by the step size each time until it is larger than the end value.

In the count loop statement, the loop variable can be used directly without the Dim statement definition, but it cannot be used again after the loop ends.


Dim count = 0 // Define the variable count

For i=1 To 100 // Each time through the loop, the variable i will increase by 1. Here the variable i does not need to be defined

count = count + i

TracePrint(count) // The result of 1+2+3+…+100 will be displayed here, which is 5050

Traverse Loop Statement

The traversal loop statement can be used to process each element in an array or dictionary. The traversal loop statement has the following two forms:

For Each cyclic variable In array or dictionary
Statement block

In this form of loop statement, each value in the array or dictionary will be traversed automatically and placed in the loop variable until the traversal is complete.


For Each cyclic variable In array or dictionary
Statement block

In this form of loop statement, each index and value in the array or dictionary will be traversed automatically and placed into loop variable 1 and loop variable 2 respectively until the traversal is complete.

Similar to the count loop statement, loop variables can be used directly without Dim statement definitions in a traversal loop statement, but they cannot be used after the loop ends.


Dim days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] // Define array variable days

Dim count = 0

For Each i In days // Each cycle, the value of variable i is each value in days

count = count + I // Add each value in the array in sequence


TracePrint(count) // The cumulative sum of the number of days in each month of the year will be displayed here, i.e. 365

Jump Statement

In the Laiye BotScript, the following forms of loop-out statements are supported:


It can only appear in the internal statement block of a loop statement such as a conditional loop, count loop, or traversal loop, which means that it immediately jumps out of the current loop.


It can only appear in the internal statement block of a loop statement such as a conditional loop, count loop, or traversal loop, meaning that the current loop ends immediately and the next loop begins.


Dim  days  =  { 'January':31, 'February':28, 'March':31,
'April':30, 'May':31, 'June':30,'July':31, 'August':31, 'November':30,'October':31, 'November':30, 'December':31 }
// Define dictionary variable days
For Each i,j In days // Each cycle, the variables i, j are each name and value in days
If j Mod 2 = 0 // If j is even
Continue // Finish the cycle and start the next one
End If
TracePrint(i) // Display the name in days (whose value is not even)

In addition, anywhere in the process block, no parameters are required to automatically end the execution of the entire process (not the current process block) when the line is executed.


A function is a grouping of commonly used functions into a block of statements (called a "definition") that can be run in other statements (called a "call"). Using functions can effectively clean up the logic and avoid duplication of code.

There is no relationship between the definition of the function and the call. The call can appear before the definition, but the function definition must be in the global space; that is, it cannot appear under other function definitions, branch statements, or loop statements.

A function definition can contain arguments, which are equivalent to variables, but the values of those variables can be specified by the caller when called.

The format of the defined function is as follows:

• Function without parameter

Function function name ()
Statement block
End Function

• Function with parameter

Function function name (parameter definition 1, parameter definition 2)
Statement block
End Function

The format of the parameter definition can be either a variable name or a variable name = expression. For the latter, it means that the parameter takes a default value, which is determined by the expression.

If the function has parameters, each variable name in the parameter is considered a local variable that has been defined in this function without the Dim statement.

The function definition needs to include the following to exit the function and return:


When this statement is executed, it will jump out of the function and return to the next line of the calling statement. You can return it with a return value (the specific function is described below). The return value is Null by default. When the execution reaches the end of the function, regardless of whether the Return statement is written or not, it will return.


Function Add(x, y=1) // Define a function with two parameters, the second parameter has a default value

Return x + y // The return value is x+y

End Function

The format of calling the function is as follows:

Return = function name (expression1, expression2)


Function name (expression1, expression2)

In the first format, a variable can be specified as the return. When the function call is completed, the return value of the function will be automatically assigned to the return variable here. The caller can learn about the function call through the return value. In this first case, the function name must be followed by parenthesis. However, with the second format, the caller does not need to return the value, so the parentheses can be omitted to make the statement more in line with natural language habits.

When a function is called, it is the equivalent of performing an assignment operation on the parameters in the function and assigning them with the value of the expression. The rules of the assignment operation are the same. When the expression is an independent (without any operator calculation) array or dictionary, the assignment operation only assigns its reference; that is, just adds an "alias" to the variable.

When a function is called, the number of expressions passed in can be less than the number of arguments. If a parameter has no incoming value or the incoming value is null, the default value is used. If there is no default value, the value is automatically Null.

For example, the function defined above can be called as follows:

a = Add(100) // Call the Add function, the second parameter takes the

default value of 1, so the value of a is 101

b = Add(100, 200) // Call the Add function, specifying two parameters, so the value of b is 300

Add 100, 200 // Call the Add function, do not care about the return value, so you do not need parentheses

After the function is defined, its name can be used as a constant of the function type, and the function name can also be assigned to a variable, and the function can also be called with this variable.

For example, the Add function defined above can be used as follows:

Dim Plus = Add

TracePrint Plus(100, 200)

// Equivalent to calling the Add function first, and then calling the TracePrint function with its return value. The result is 300

In addition to the functions defined in the process block, the Laiye BotScript has many built-in functions that can perform a variety of rich functions. For example, TracePrint in the example above is a built-in function.


Multiple Modules

The Laiye BotScript supports multiple modules, which can be implemented in other languages and used in the current process block. The following types of modules are currently supported: 1) Process blocks for the Laiye BotScript; 2) Modules of Python language; 3) C/C++ language module; 4) .NET module; 5) Modules of Lua language. Different modules have different extensions, and when the extension is removed, the filename is the module name. For example, a Python module whose file name is has a module name of Rest.

In the Laiye BotScript, import a module in the following way:

Import Module name

Note that the module name is written in the same way as the variable name, without double quotation marks or extensions such as the Import Rest. When Laiye RPA is compiled and run, it will automatically search according to the order of Lua module, C module,.NET module, Python module, Laiye BotScript process block, and the corresponding extension. In Windows, because the file name is not case sensitive, the module name following the Import statement can also be case insensitive. In other operating systems, you need to pay attention to the case of the module name and the file.

Each imported module will be placed in a "namespace" with the same name as the module name. The functions in the imported module can be called in the following way:

Namespace. Function name

A dot (.) is added between the namespace and the function name.

For Python and Lua language modules, only global variable definitions and function definitions will be retained, and other content will be ignored. For C modules and .Net modules, only the functions defined therein can be called.

If you want to import a Laiye BotScript process block, you need to import the imported process block file in the same directory. After importing the Laiye BotScript process block, you can either call the function defined in the imported process block, or directly use the name of the process block as the function name to directly run all the commands in this process block. For example, there is a process block ABC.task. After importing in other process blocks, you can directly invoke ABC.Task (equivalent to running the process block ABC.Task) in the following format:


Assuming a function is defined in the process block ABC.task, named test, you can call this function in the following format



As a dynamically typed language, there are many errors that are difficult to check at compile time and can only be reported at run time. Moreover, since Laiye RPA does not emphasize the speed of operation but more emphasis on the stability of operation, more checks will be added during operation. When an error occurs, an appropriate way to report an error is to throw an exception. For example, when running a target command (the concept of "target command" can refer to [here][target selection]), if the target cannot be found within the timeout period, an exception will be automatically thrown.

In addition to this automatic exception, you can also use the Throw statement to throw an exception:

Throw String

When an exception is thrown, the error can be thrown in the form of a string, or the string can be omitted.

If the exception is not handled in the process block, when an exception occurs, the entire process will be terminated, and the exception-related information will be displayed. As shown below:

**Figure 2: An exception occurs when the process is running**

If you do not want the process to terminate when an exception occurs, you can use the following statement to handle the exception:

Statement block
Catch variable name
Statement block
Statement block
End Try

If an exception occurs in the statement block after Try, it will jump to and execute the statement block after Catch. If no exception occurs in the Try statement block, and the Else statement block is defined (of course, the Else statement block can also be omitted), it will jump to the Else statement block for execution.

The variable name after the Catch statement can be omitted. If it is not omitted, it can be defined in advance without the Dim statement. When an exception occurs, the value of this variable is a dictionary, which contains three fields "File", "Line", and "Message", respectively representing the filename of the exception, the Line number of the exception, and the information contained in the exception.