I'm trying to use toJSON and fromJSON to maintain a settings file that can be manually edited by humans (mostly for testing purposes) but which my program will also read on startup and write when the user changes the settings in the (not yet created) settings menu. Ideally I would like to save several JSON records as individual strings in the one text file, but at the moment I only have one string I'm trying to save, because even that isn't working yet.
Here is my problem code:
//saves the settings record to a file as a plain string
function SaveDisplaySettings()
fileID as integer
//File will be created if it doesn't exist
fileID = OpenToWrite("settings.txt", 0)
settingsString as string
settingsString = displaysettings.toJSON() //makes a string from settings
WriteLine(fileID, settingsString)
CloseFile(fileID)
endfunction settingsString
//loads the settings from plain JSON to the settings record
function LoadDisplaySettings()
fileID as integer
fileID = OpenToRead("settings.txt")
settingsString as string
settingsString = ReadLine(fileID) //read the settings string
//displaySettings.fromJSON(settingsString)
CloseFile(fileID)
endfunction settingsString
displaySettings is a global record that holds a bunch of info used by ApplyDisplaySettings() to set the screen width and height and so on. These two functions return settingsString because I needed to figure out why I kept getting the message "unexpected end of object" when I ran LoadSettings. SaveSettings seems to work just fine: it saves a human-readable string to a text file that represents the displaySettings record. LoadSettings seems to load the first bracket, but not the rest of the string. It seems to literally read "{" instead of the whole string.