Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- turtle.dig()
- local commands = {
- ["w"] = function ()
- while not turtle.forward() do
- turtle.dig()
- end
- end,
- ["s"] = function ()
- turtle.back()
- end,
- ["a"] = function ()
- turtle.turnLeft()
- turtle.dig()
- end,
- ["d"] = function ()
- turtle.turnRight()
- turtle.dig()
- end,
- ["q"] = function ()
- while not turtle.down() do
- turtle.digDown()
- end
- end,
- ["e"] = function ()
- while not turtle.up() do
- turtle.digUp()
- end
- end,
- }
- local function doCommand(cmd)
- local func = commands[cmd]
- if not func then
- return false, string.format("No such command: '%s'", cmd)
- end
- func()
- return true
- end
- while true do
- local input = read()
- for i=1, #input do
- local success, message = doCommand(input:sub(i, i))
- if not success then
- print(string.format("Command interrupted at #%s", i))
- print(message)
- return
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement