Advertisement
antonsavov

Untitled

Mar 6th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. os.loadAPI('json')
  2.  
  3. --test reading nad writing the buildzones grid to a file
  4. --creates a grid of absolute references (0,0) (1,0)
  5. function buildGrid(w,h)
  6. local grid = {}
  7. for x=0,w-1 do
  8. for z=0,h-1 do
  9. table.insert(grid,{x=x,z=z,played=false})
  10. end
  11. end
  12. return grid
  13. end
  14.  
  15. local LOCS = buildGrid(11,27)
  16.  
  17. fs.makeDir("/records")
  18. local filename = "/records/_buildzones-list.yaml"
  19.  
  20. local file = fs.open(filename,"w")
  21. file.write(json.encodePretty(LOCS))
  22. file.close()
  23.  
  24. local newLOCS = json.decodeFromFile(filename)
  25. print(#newLOCS)
  26. print(newLOCS[0])
  27. print(newLOCS[0].x)
  28. print(newLOCS[0].z)
  29. print(newLOCS[0].played)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement