View difference between Paste ID: uVG60EGG and 9MAefhvi
SHOW: | | - or go back to the newest paste.
1
turtle.dig()
2
3
local commands = {
4-
  local rawCmd = read()
4+
  ["w"] = function ()
5-
  for _, cmd in ipairs(rawCmd) do
5+
    while not turtle.forward() do
6-
  if (cmd == "w") then
6+
      turtle.dig()
7
    end
8-
    turtle.forward()
8+
  end,
9-
  elseif (cmd == "d") then
9+
  ["s"] = function ()
10
    turtle.back()
11
  end,
12-
  elseif (cmd == "s") then
12+
  ["a"] = function ()
13
    turtle.turnLeft()
14-
  elseif (cmd == "a") then
14+
15
  end,
16
  ["d"] = function ()
17-
  elseif (cmd == "e") then
17+
18-
    turtle.digUp()
18+
19-
    turtle.up()
19+
  end,
20-
  elseif (cmd == "q") then
20+
  ["q"] = function ()
21-
    turtle.digDown()
21+
    while not turtle.down() do
22-
    turtle.down()
22+
      turtle.digDown()
23
    end
24
  end,
25
  ["e"] = function ()
26
    while not turtle.up() do
27
      turtle.digUp()
28
    end
29
  end,
30
}
31
32
local function doCommand(cmd)
33
  local func = commands[cmd]
34
  if not func then
35
    return false, string.format("No such command: '%s'", cmd)
36
  end
37
  func()
38
  return true
39
end
40
41
while true do
42
  local input = read()
43
  for i=1, #input do
44
    local success, message = doCommand(input:sub(i, i))
45
    if not success then
46
      print(string.format("Command interrupted at #%s", i))
47
      print(message)
48
      return
49
    end
50
  end
51
end