Advertisement
Espen

Turtle Events API Test-Program

Mar 20th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. -- Load API
  2. os.loadAPI("tev")
  3. if not tev then
  4.   error( "Turtle Event API not loaded!" )
  5. end
  6.  
  7. --[[ === MAIN LOOP === ]]
  8. while true do
  9.   local event, p1, p2, p3, p4 = re.pullEvent()
  10.  
  11.   if event == "turtle" then
  12.     print( event..", "..tostring( p1 )..", "..tostring( p2 )..", "..tostring( p3 )..", "..tostring( p4 ) )
  13.   end
  14.  
  15.   -- Moving
  16.   if event == "key" and p1 == 200 then tev.forward() end  -- UP
  17.   if event == "key" and p1 == 208 then tev.back() end  -- DOWN
  18.   if event == "key" and p1 == 57 then tev.up() end  -- SPACE
  19.   if event == "key" and p1 == 42 then tev.down() end  -- LSHIFT
  20.   if event == "key" and p1 == 203 then tev.turnLeft() end  -- LEFT
  21.   if event == "key" and p1 == 205 then tev.turnRight() end  -- RIGHT
  22.   -- Placing
  23.   if event == "key" and p1 == 71 then tev.placeUp() end  -- NUMPAD 7
  24.   if event == "key" and p1 == 75 then tev.place() end  -- NUMPAD 4
  25.   if event == "key" and p1 == 79 then tev.placeDown() end  -- NUMPAD 1
  26.   -- Detecting
  27.   if event == "key" and p1 == 72 then tev.detectUp() end  -- NUMPAD 8
  28.   if event == "key" and p1 == 76 then tev.detect() end  -- NUMPAD 5
  29.   if event == "key" and p1 == 80 then tev.detectDown() end  -- NUMPAD 2
  30.   -- Digging
  31.   if event == "key" and p1 == 73 then tev.digUp() end  -- NUMPAD 9
  32.   if event == "key" and p1 == 77 then tev.dig() end  -- NUMPAD 6
  33.   if event == "key" and p1 == 81 then tev.digDown() end  -- NUMPAD 3
  34.   -- Comparing
  35.   if event == "char" and string.lower( p1 ) == "q" then tev.compareUp() end
  36.   if event == "char" and string.lower( p1 ) == "a" then tev.compare() end
  37.   if event == "char" and string.lower( p1 ) == "y" then tev.compareDown() end
  38.   -- Dropping
  39.   if event == "char" and string.lower( p1 ) == "g" then tev.drop() end
  40.   if event == "char" and string.lower( p1 ) == "b" then tev.drop(5) end
  41.   -- Selecting
  42.   if event == "char" and string.lower( p1 ) == "x" then tev.select(1) end
  43.   if event == "char" and string.lower( p1 ) == "c" then tev.select(2) end
  44.   -- Stopping program
  45.   if event == "char" and string.lower( p1 ) == "e" then break end
  46. end
  47.  
  48. -- Cleanup
  49. os.unloadAPI( tev )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement