Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI('json')
- --test reading nad writing the buildzones grid to a file
- --creates a grid of absolute references (0,0) (1,0)
- function buildGrid(w,h)
- local grid = {}
- for x=0,w-1 do
- for z=0,h-1 do
- table.insert(grid,{x=x,z=z,played=false})
- end
- end
- return grid
- end
- local LOCS = buildGrid(11,27)
- fs.makeDir("/records")
- local filename = "/records/_buildzones-list.yaml"
- local file = fs.open(filename,"w")
- file.write(json.encodePretty(LOCS))
- file.close()
- local id = 10
- local newLOCS = json.decodeFromFile(filename)
- print(#newLOCS)
- print(newLOCS[id].x)
- print(newLOCS[id].z)
- print(newLOCS[id].played)
- newLOCS[id].played = false
- local file = fs.open(filename,"w")
- file.write(json.encodePretty(newLOCS))
- file.close()
- local changedLOCS = json.decodeFromFile(filename)
- print(#changedLOCS)
- print(changedLOCS[id].x)
- print(changedLOCS[id].z)
- print(changedLOCS[id].played)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement