View difference between Paste ID: 9weNSjGW and qRCrx2c8
SHOW: | | - or go back to the newest paste.
1
-- List of actions
2-
  _,key = os.pullEvent("char")
2+
-- button & function
3-
  if key == "r" then
3+
local action = {
4-
    turtle.refuel()
4+
  r = turtle.refuel,
5-
  elseif key == "w" then
5+
  w = turtle.forward,
6-
    turtle.forward()
6+
  s = turtle.back,
7-
  elseif key == "s" then
7+
  a = turtle.turnLeft,
8-
    turtle.back()
8+
  d = turtle.turnRight,
9-
  elseif key == "a" then
9+
  q = turtle.down,
10-
    turtle.turnLeft()
10+
  e = turtle.up,
11-
  elseif key == "d" then
11+
  z = turtle.digDown,
12-
    turtle.turnRight()
12+
  x = turtle.dig,
13-
  elseif key == "q" then
13+
  c = turtle.digUp,
14-
    turtle.down()
14+
  v = turtle.placeDown,
15-
  elseif key == "e" then
15+
  b = turtle.place,
16-
    turtle.up()
16+
  n = turtle.placeUp,
17-
  elseif key == "z" then
17+
}
18-
    turtle.digDown()
18+
19-
  elseif key == "x" then
19+
20-
    turtle.dig()
20+
  ev,key = os.pullEvent()
21-
  elseif key == "c" then
21+
22-
    turtle.digUp()
22+
  -- Run the function assigned to the variable inside "action"
23-
  elseif key == "v" then
23+
  if ev == "char" then
24-
    turtle.placeDown()
24+
    action[key] then action[key]()
25-
  elseif key == "b" then
25+
26-
    turtle.place()
26+
  -- Selection, supports slots 1 to 10
27-
  elseif key == "n"  then
27+
  elseif ev == "key" then
28-
    turtle.placeUp()
28+
    if key >= 2 or key <= 11 then
29-
  elseif tonumber(key) + 0 == tonumber(key) then
29+
      turtle.select(key-1)
30-
    turtle.select(tonumber(key))
30+
    end
31
  end
32
end