Advertisement
Ltven0mI

TurtleMine

Mar 30th, 2023
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. turtle.dig()
  2.  
  3. local commands = {
  4.   ["w"] = function ()
  5.     while not turtle.forward() do
  6.       turtle.dig()
  7.     end
  8.   end,
  9.   ["s"] = function ()
  10.     turtle.back()
  11.   end,
  12.   ["a"] = function ()
  13.     turtle.turnLeft()
  14.     turtle.dig()
  15.   end,
  16.   ["d"] = function ()
  17.     turtle.turnRight()
  18.     turtle.dig()
  19.   end,
  20.   ["q"] = function ()
  21.     while not turtle.down() do
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement