select chapter

laiye rpa developer guide d1-凯发网站

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.

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= \
1


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.

e.g:

// here
/*
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 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.

e.g:

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.

e.g:

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.

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.

e.g:

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.

the operators and their meanings in laiye botscript are as follows:

-

*

/

addition

subtraction/negation

multiplication

division


&

^

< 

<=

concatenation string

exponentiation

less than

less than or equal to


> 

>=

<> 

=

            

greater than

greater than or equal to

unequal

equal/valuation


and

or

not

mod

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:

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
else
  statement block2
end if

if condition 1
  statement block1
elseif condition 2
  statement block2
else
  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.

e.g:

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

e.g:

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

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

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

    do
      statement block
    loop

e.g:

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
next

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.

e.g:

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
next


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.

or:

for each cyclic variable in array or dictionary
  statement block
next


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.

e.g:


in the laiye botscript, the following forms of loop-out statements are supported:

break


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.

continue


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.

e.g:

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:

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.

e.g:

the format of calling the function is as follows:

return = function name (expression1, expression2)


or

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.

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 rest.py 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:

abc()


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

abc.test()


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:

try
   statement block
catch variable name
   statement block
else
   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.

网站地图