Advertisement
lavalevel

broken saveload

Aug 9th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1.  
  2.  
  3.       savefile = maps[toload].. ".txt"
  4.       print (savefile)  -- prints fooWorld.txt
  5.       _disk.saveTable( map2process, savefile, system.ResourceDirectory  )
  6.  
  7. ---- here is the loadsave mod
  8.  
  9. local this = {}
  10. --local json = require("json")
  11. local json = require "json"
  12. local DefaultLocation = system.DocumentsDirectory
  13. local RealDefaultLocation = DefaultLocation
  14. local ValidLocations = {
  15.    [system.DocumentsDirectory] = true,
  16.    [system.ResourceDirectory] = true,
  17.    [system.CachesDirectory] = true,
  18.    [system.TemporaryDirectory] = true
  19. }
  20.  
  21. function this.saveTable(t, filename, location)
  22.     print ("  STUFF 'SAVED' to DISK ")
  23.     if location and (not ValidLocations[location]) then
  24.      error("Attempted to save a table to an invalid location", 2)
  25.     elseif not location then
  26.       location = DefaultLocation
  27.     end
  28.    
  29.     local path = system.pathForFile( filename, location)
  30.     local file = io.open(path, "w")
  31.     if file then
  32.         local contents = json.encode(t)
  33.         file:write( contents )
  34.         io.close( file )
  35.         return true
  36.     else
  37.         print ("cant find:" .. t,filename,location)
  38.         return false
  39.     end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement