Advertisement
USMCDefender

Untitled

Jan 6th, 2021
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. rednet.open("left")
  2. os.loadAPI('json')
  3. function get()
  4.    local object = json.decodeFromFile("bot/cords.json")
  5.    cords = {object["x"], object["y"], object["z"], object["direction"]}
  6. end
  7.  
  8. function add_to_cords(x, y, z)
  9.     old_cords = get()
  10.     old_x = old_cords[1]
  11.     old_y = old_cords[2]
  12.     old_z = old_cords[3]
  13.     dir = old_cords[4]
  14.     x = tostring(tonumber(old_x) + x)
  15.     y = tostring(tonumber(old_y) + y)
  16.     z = tostring(tonumber(old_z) + z)
  17.     obj = "{\n \"x\": \"" .. tostring(x) .. "\",\n \"y\": \"" .. tostring(y) .. "\",\n \"z\": \"".. tostring(z) .. "\",\n \"direction\": \"" .. tostring(dir) .. "\"\n}"
  18.     f = fs.open("bot/cords.json", 'w')
  19.     f.write(obj)
  20.     f.close()
  21.     print(obj)
  22.     sleep(2)
  23. end
  24.  
  25. function turnLeft()
  26.    
  27. end
  28.  
  29. function turnRight()
  30.  
  31. end
  32.  
  33. function forward()
  34.    
  35. end
  36.  
  37. function back()
  38.    
  39. end
  40.  
  41. while true do
  42.     sender, message, method = rednet.receive()
  43.     if message == "w" then
  44.             turtle.forward()
  45.         elseif message == "s" then
  46.             turtle.back()
  47.         elseif message == "a" then
  48.             turtle.turnLeft()
  49.         elseif message == "d" then
  50.             turtle.turnRight()
  51.         elseif message == "r" then
  52.             turtle.refuel()
  53.     end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement