So I have a created a switch widget. I have managed to record the values of the switch (true or false) to a text file in the documents directory.
So the switch works and records the correct values in the text file.
I have also created (per object:setSelected()) a variable (file1) that I can place into the “isOn” state so the state of the switch can change dynamically. The problem is that the switch state always defaults to on/true, even when the text file has off/false.
I am doing something very wrong… Please help.
Code:
[lua] local path = system.pathForFile( “sound.txt”, system.DocumentsDirectory )
local file1 = io.open( path, “r” )
for line in file1:lines() do
print( line )
end
onOffSwitch:setState{ isOn = (file1), isAnimated = true, onComplete = print(“COMPLETE”)}[/lua]
I hope that made sense. If not, please let me know and I will try to clarify…
I basically want the switch to: initially default to on, then if switched to off, remember that position at a later time. This is my own way of creating a “simple” settings page. ha…
Thanks in advance!