Advertisement
lavalevel

JSON grief...

Jan 23rd, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. local path = system.pathForFile( "Version.txt", system.DocumentsDirectory )
  2.  
  3. -- io.open opens a file at path. returns nil if no file found
  4. local file = io.open( path, "r" )
  5. if file then
  6.    -- read all contents of file into a string
  7.    local contents = file:read( "*a" )
  8.  
  9.    local decodeVersion = json.decode(contents)
  10.  
  11.    -- print( "Contents of " .. path .. "\n" .. contents )
  12.    io.close( file )
  13.    layout.elements.Text_VersionNumber.text = ( gameInstallation[1] )
  14. else
  15.    -- create file b/c it doesn't exist yet    <------ The game Version
  16.    file = io.open( path, "w" )
  17.    local gameInstallation = {Version = .07, SaveDisk = 0 }
  18.  
  19.    local encodedVersion = json.encode (gameInstallation)
  20.  
  21.    file:write( gameInstallation )
  22.    for _,v in ipairs( gameInstallation ) do file:write( v, " " ) end
  23.    file:write( "\nNo more data\n" )
  24.    io.close( file )
  25.  
  26.    -- layout.elements.Text_VersionNumber.text = ( ) )
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement