Advertisement
albrat

Turtle Wireless Mover

Jun 29th, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. -- local debug = true
  2. local cmpid = os.getComputerID()  -- get the computer / turtle ID
  3. print(cmpid) -- Print the Tutle / computer ID   (this is always good to show and know)
  4. rednet.open("right")
  5.  
  6. -- event is the computer event code eg. "rednet_message" which is what we are looking for.
  7. -- p1 is our senders computer ID.
  8. -- p2 is our senders message.
  9. -- p3 is our senders distance from the turtle.
  10.  
  11.  
  12. while true do  -- Loop Infinitely
  13.   local event,p1,p2,p3 = os.pullEvent()  -- Pull event with args.
  14.   if debug and event == "rednet_message" then  -- only if we are debugging the script  execute this
  15.     print( event .. " " .. p1 .. " " .. p2 .. " " .. p3 ) -- debug screen output on Turtle
  16.   end
  17.  
  18.   if event == "rednet_message" then -- only if the event is a rednet incoming message do anything, otherwise return to loop waiting.
  19.     rednet.send(p1,"ack") -- reply to say we received the message
  20.     if debug then print("ack " .. p2 );end
  21.     if p2 == "left" then
  22.      if debug then print("l ");end
  23.      turtle.turnLeft()
  24.      
  25.     elseif p2 == "right" then
  26.      if debug then print("r ");end
  27.      turtle.turnRight()
  28.      
  29.     elseif p2 == "back" then
  30.      if debug then print("b ");end
  31.      turtle.back()
  32.      
  33.     elseif p2 == "forward" then
  34.      if debug then print("f ");end
  35.      turtle.forward()
  36.      
  37.     elseif p2 == "up" then
  38.      if debug then print("u ");end
  39.      turtle.up()
  40.      
  41.     elseif p2 == "down" then
  42.      if debug then print("d ");end
  43.      turtle.down()
  44.      
  45.     elseif p2 == "dig" then
  46.      if debug then print("dig ");end
  47.      turtle.dig()
  48.      
  49.     elseif p2 == "return" then  -- for now we only want the turtle to return to the ground level...
  50.      for x=1,20 do
  51.       turtle.down()
  52.      end
  53.     end
  54.   end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement