Lion4ever

remote turtle control program

Mar 13th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 KB | None | 0 0
  1. local running = true
  2. write("Target: ")
  3. local id = tonumber(read()) or 1
  4. rednet.open("back")
  5. local key = {[16]="up",[17]="forward",[18]="down",[30]="turnLeft",[31]="back",[32]="turnRight",[36]="digUp",[37]="dig",[38]="digDown",[22]="placeUp",[23]="place",[24]="placeDown",[28]="end",[57]="stop"}
  6.  
  7. local pressed = {}
  8. local function listen()
  9.   while running do
  10.     local f = key[({os.pullEvent("key")})[2]]
  11.     if f == "end" then
  12.     running = false
  13.     elseif f== "stop" then
  14.     pressed = {}
  15.     elseif f then
  16.       table.insert(pressed,1,f)
  17.     end
  18.   end
  19. end
  20.  
  21. local function execute()
  22.   while running do
  23.     while #pressed == 0 do
  24.       os.pullEvent()
  25.     end
  26.     rednet.send(id,pressed[#pressed])
  27.     table.remove(pressed)
  28.     sleep(0.45)
  29.   end
  30. end
  31.  
  32. parallel.waitForAny(listen,execute)
Advertisement
Add Comment
Please, Sign In to add comment