Using Multiple Script Files
It is often useful to modularize code by separating it into multiple script files. This can aid when debugging as functionality can be easily isolated to help in identifying trouble code.
A new script file can be created by using the Project tab in OpenBots Studio. By right-clicking on the project folder and selecting the ‘New Script File’ option will open the prompt for creating a new .obscript file that can be used during the current project.
Ensure to provide a unique name for the newly created script file, ensuring to leave the .obscript extension in the file name provided.
When using multiple script files, it is often necessary to pass data back and forth between them. However, in OpenBots, variables only exist within the script files that they were created. To exchange data successfully, Arguments can be utilized instead and work similarly to variables. They can be created in the newly created script files by using the ‘Arguments Manager’ located in the ‘Options’ tab on the tool bar or can be created directly using the Arguments tab located in the bottom of OpenBots Studio.
There are 3 types of arguments that can be created and used.
- In-Arguments: Arguments created in the ‘In’ direction. These are used to pass data into the current script file from the calling one. (Example: If in the Main file the second script file is called and will be passing data to the second script, this is done by creating an ‘In’ direction argument in the second script file)
- Out-Arguments: Arguments created in the ‘Out’ direction. These are used to pass data from the current script file to the initial calling one. (Example: If the Main file called the second script file and it will be passing data back to the Main file, this requires an ‘Out’ direction argument to be created in the second script file)
- In-out Argument: Arguments created in the ‘InOut’ direction. These are used to initially accept data from the calling script file, then pass an updated value back to the calling script once finished. (Example: If the Main file calls the second script file and the Main file contains a value that must be updated and then returned by the second script file, this requires an ‘InOut’ direction argument to be created in the second script file)
When executing the code, OpenBots Studio will execute the currently selected script file. However, once the code is deployed to OpenBots Server, the code will always begin from the Main.obscript file. To instruct the automation to execute another script file, the ‘Run Task’ command is used. This command requires users to specify the script file that should be executed at that point in the automation. It also includes a toggle that can be used to assign values to the arguments that exist in the script file.