Definition
string ReadStringVariableFromFile()
Description
This function reads a string variable from the currently open file. Before reading information from the file, make sure that you have opened the desired file for reading with the OpenFileForReading function.
Return Value
This function returns a string.
Example
sVar = "init" function Init() --Create a folder in Assets/Data/ path CreateFolder("Lev1") --Create and open file to write data OpenFileForWriting("Lev1/level1.bin") WriteStringVariableToFile("level1") CloseFile("Lev1/level1.bin") --Open File to load data OpenFileForReading("Lev1/level1.bin") sVar = ReadStringVariableFromFile() CloseFile("Lev1/level1.bin") end
First, using the CreateFolder function, we create a folder called “Lev1” in the Assets/Data/ path. Then, using the OpenFileForWriting function, we open the level1.bin file located in the Assets/Data/Lev1/ path for writing. After writing a string value by the WriteStringVariableToFile function, we close the file by the CloseFile function.
Then, using the OpenFileForReading function, we open the level1.bin file located in the path Assets/Data/Lev1/ for reading and read a string variable from the level1.bin file with the ReadStringVariableFromFile() function. In our example, value of sVar is “level1” after reading it. Finally, we close the file by the CloseFile function.
ReadStringVariableFromFile