Advertisement
Selim_042

turtleCar

Feb 26th, 2015
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. if os.loadAPI("turtleCar") then
  2. --  compass = peripheral.find("compass")
  3.   modem = peripheral.find("modem")
  4.   modem.open(55)
  5.   actions = 0
  6.   while true do
  7.     term.clear()
  8.     term.setCursorPos(1, 1)
  9. --    dir = turtleCar.getDir(compass)
  10. --    coords = turtleCar.getCoords()
  11. --    print("Turtle is currently facing "..dir)
  12. --    print("Turtle is at "..coords[1]..", "..coords[2]..", "..coords[3])
  13.     print("Performed "..actions.." actions")
  14.     e, side, sendCh, replyCh, msg, dist = os.pullEvent("modem_message")
  15.     if msg == "l" then
  16.       turtleCar.left()
  17.       actions = actions + 1
  18.     elseif msg == "r" then
  19.       turtleCar.right()
  20.       actions = actions + 1
  21.     elseif msg == "u" then
  22.       turtleCar.up()
  23.       actions = actions + 1
  24.     elseif msg == "d" then
  25.       turtleCar.down()
  26.       actions = actions + 1
  27.     elseif msg == "update" then
  28.       shell.run("updateCar")
  29.     elseif (tonumber(msg) > 0) or (tonumber(msg) < 0) then
  30.       if msg > 0 then
  31.         turtleCar.forward(msg)
  32.         actions = actions + 1
  33.       elseif msg < 0 then
  34.         turtleCar.backward((msg * -1))
  35.         actions = actions + 1
  36.       end
  37.     end
  38.     msg = nil
  39. --    turtleCar.writeCoords(coords)
  40.   end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement