Advertisement
Guest User

my.lua

a guest
Apr 9th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.74 KB | None | 0 0
  1. local my = {}
  2.  
  3. function my.hello()
  4.   print("hello")
  5. end
  6.  
  7. local robot = require("robot")
  8. local json = require("json")
  9. local filesystem = require("filesystem")
  10. local args = {...}
  11.  
  12. local saveFile = "navPos.txt"
  13. local position = {1, 2, 1}
  14.  
  15. local this = {}
  16.  
  17. function this.load()
  18.   local f = io.open(saveFile, "r")
  19.   if f == nil then
  20.     print("Save file not found")
  21.     return
  22.   end
  23.  
  24.   local encoded = f:read()
  25.   local position = json.decode(encoded)
  26.   f:close()
  27.  
  28.   print("Loaded position: "..encoded)
  29. end
  30.  
  31. function this.save()
  32.   local f = io.open(saveFile, "w")
  33.   local encoded = json.encode(position)
  34.   f:write(encoded)
  35.   f:close()
  36.   print("Saved position: "..encoded)
  37. end
  38.  
  39. function my.forward(count)
  40.   for i=0,count do
  41.     robot.forward()
  42.   end
  43. end
  44.  
  45. return my
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement