--------------------------------------------------- 
-- FBA Tutorials
--
-- Tutorial / 11 / Handling configurations files
--
--------------------------------------------------- 
--
-- This sample shows you how to save and load data
-- from a configuration file
--
--------------------------------------------------- 



-- open a configuration file
openconfig("myconfig.ini")

-- read value from config file
local current = readconfignumber("general", "mynum", 0)

local mystr = readconfigstring("general", "mystring", "")


function onmainloop()	

         clear(0,0,0)
 
         print(20, 20, "Use key/right keys to change value", 255, 255, 255)
         print(20, 40, "Current value " .. current, 255, 0, 0)
         print(20, 100, "Then quit and reopen this application", 255, 255, 255)
         print(20, 120, "You will see the last value you selected", 255, 255, 255)
         print(20, 140, "before you quit.", 255, 255, 255)
         print(20, 160, "Values are saved inside config file", 255, 255, 255)
         
         print(20, 200, mystr, 0, 0, 255)

         if numkeypress( keyleft() ) > 0 then
            current = current - 1
         end
         if numkeypress( keyright() ) > 0 then
            current = current + 1
         end
                  
         if (mousedown() > 0) then
            quit()
         end
end

--
-- when the application is going to close, we write the config..
--
function onquit()
    --
    -- config files are similar to Windows .ini files
    -- They are composed by sections and keys:
    --
    -- [Section]
    -- Key=value
    --
    writeconfignumber("general", "mynum", current)

end
