ecco7777

position remembering turtle functions

Apr 17th, 2020
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. --position remembering turtle
  2.  
  3. t=[]
  4.  
  5. function setup()
  6.     if fs.exist("position") then
  7.         getPos()
  8.     else
  9.         pos=[]
  10.         print("X Position?")
  11.         pos.x=tonumber(io.read)
  12.         print("Y Position?")
  13.         pos.y=tonumber(io.read)
  14.         print("Z Position?")
  15.         pos.z=tonumber(io.read)
  16.         print("Heading? (N,E,S,W)")
  17.         pos.h=io.read
  18.         savePos()
  19.     end
  20.     hctohn=['N','E','S','W']
  21.     hntohn=[]
  22.     hntohn['N']=1
  23.     hntohn['E']=1
  24.     hntohn['S']=1
  25.     hntohn['W']=1
  26.     heading=[]
  27.     heading['N']=1
  28.     heading['E']=1
  29.     heading['S']=-1
  30.     heading['W']=-1
  31. end
  32.  
  33. function t.turnRight()
  34.     if hctohn[pos.h] then
  35.        
  36.     end
  37. end
  38.  
  39. function t.forward()
  40.     if turtle.forward() then
  41.        
  42.     end
  43. end
  44.  
  45. function getVar(file, var)
  46.     h=fs.open(file,"r")
  47.     var=tonumber(h.readLine())
  48.     h.close()
  49. end
  50.  
  51. function saveVar(file, var)
  52.     h=fs.open(file,"w")
  53.     h.writeLine(var)
  54.     h.close()
  55. end
  56.  
  57. function saveArray(file, var)
  58.     h=fs.open(file,"w")
  59.     h.writeLine(textutils.serialize(var))
  60.     h.close()
  61. end
  62.  
  63. function getArray(file, var)
  64.     h=fs.open(file,"r")
  65.     var=textutils.unserialize(h.readLine())
  66.     h.close()
  67.     return var
  68. end
  69.  
  70. function getPos()
  71.     pos=getArray("position",pos)
  72. end
  73.  
  74. function savePos()
  75.     saveArray("position",pos)
  76. end
Add Comment
Please, Sign In to add comment