Script Examples
Reading data from File
In this example, we created a UI that reads data from a CSV file.
The script:
- reads the file,
- splits its content by rows,
- stores the values in an array.
These values are then assigned to the corresponding text fields to display the data dynamically.
The CSV file
Create a file named PlayerInfo.csv on the Erizos Studio Server machine. The script below reads five columns per row, in this order: first name, age, position, height and the path of the player image.
1 2 3 4 | |
Warning
File.read passes the filename straight to the file system of the Erizos Studio Server, with no root folder prepended. A bare filename therefore resolves against the working directory of the Studio Server process, which is not a location you should rely on. Use an absolute path, as the example does below.
The User Interface
The script expects the following controls:
dropdown1- a Dropdown, populated from the first column of the fileFirstName_TI,Age_TI,Position_TI,Height_TI- Text inputsPlayerImage_Media- a Media or Media Browser control
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
Info
A UI Builder script body may use await at the top level, as the first line does - the whole script is compiled into an async function.
Tip
selectedIndex is derived from the dropdown's current value, so two rows whose first column is identical both resolve to the first of the two. Make sure the column you feed to addItem is unique.
The File API
| Call | Description |
|---|---|
File.read(filename, encoding?) |
Reads a file and resolves to its contents as a string. encoding defaults to utf8. Throws File '<name>' does not exists when the path cannot be found. |
File.write(filename, data, encoding?) |
Writes data to the file. |
File.list(folder) |
Resolves to the list of names inside a folder. |
All three are executed by the Erizos Studio Server, so the paths are the server's paths, not the operator's.
