Select chapter

1. 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.

1.1 Overview

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.png
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.

1.2 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.

1.3 Variables, Constants and Types of Data

1.3.1 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.



1.3.2 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.



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.

1.3.3 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.

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.

1.4 Operators and Expressions

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













Concatenation string


Less than

Less than or equal to






Greater than

Greater than or equal to







Logic AND

Logic OR

Logic Not

Take 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:


1.5 Logical Statement

1.5.1 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.



1.5.2 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



1.5.3 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

  2. 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

  3. 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

  4. 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

  5. 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



1.5.4 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.



1.5.5 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.



1.5.6 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.



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.

1.6 Function

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.



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:


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:


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.

1.7 Other

1.7.1 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


1.7.2 Exception

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.png
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.