How To | Writing a .txt File To a Core Using Lua
Writing a .txt file to a Core using Lua can be used for any number of applications involving regular changes to text information within a design without needing to change the overall architecture The following steps describe how to create the reference needed to utilize a .txt file for these purposes.
Procedure
- Open Core Manager and go to the Files Menu.
- Add a directory. ("My Files" is used in the example below)
- Open Q-SYS Designer, then drag in a a script component.
- Insert the code below in the script component, then Save to Core and Run
This will write a file named "Test File.txt" to the Core's media directory in the My Files sub-directory. This will also print the contents of the file to the debug output.
Example Script
file = io.open("media/My Files/Test File.txt", "w") file:write("Line1\n","Line2\n","Line3\n") file:close() --Read from a file file = io.open("media/My Files/Test File.txt", "r") for c in file:lines() do print(c) end file:close()