Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function create(whileFunction, action, before, after)
- return function()
- if before then
- before()
- end
- while whileFunction() do
- action()
- os.sleep(0.5)
- end
- if after then
- after()
- end
- end
- end
- local mapping = {}
- -- All the move actions
- mapping["f"] = create(turtle.detect, turtle.dig, nil, turtle.forward)
- mapping["l"] = create(turtle.detect, turtle.dig, turtle.turnLeft, turtle.forward)
- mapping["r"] = create(turtle.detect, turtle.dig, turtle.turnRight, turtle.forward)
- mapping["u"] = create(turtle.detectUp, turtle.digUp, nil, turtle.up)
- mapping["d"] = create(turtle.detectDown, turtle.digDown, nil, turtle.down)
- mapping["b"] = turtle.back
- -- Turn direction
- mapping["tl"] = turtle.turnLeft
- mapping["tr"] = turtle.turnRight
- mapping["ta"] = function() turtle.turnLeft() turtle.turnLeft() end -- turn around
- -- All the dig actions
- mapping["df"] = create(turtle.detect, turtle.dig)
- mapping["dl"] = create(turtle.detect, turtle.dig, turtle.turnLeft)
- mapping["dr"] = create(turtle.detect, turtle.dig, turtle.turnRight)
- mapping["du"] = create(turtle.detectUp, turtle.digUp)
- mapping["dd"] = create(turtle.detectDown, turtle.digDown)
- -- All the place actions
- mapping["pf"] = turtle.place
- mapping["pd"] = turtle.placeDown
- mapping["pu"] = turtle.placeUp
- function move(moveString)
- for cur in moveString:gmatch("%S+") do
- mapping[cur]()
- end
- end
- function repeatMoves(moveString, amount)
- for i = 1, amount do
- move(moveString)
- end
- end
- function moveRelative(forward, up)
- if(forward < 0) then
- repeatMoves("b", -1 * forward)
- else
- repeatMoves("f", forward)
- end
- if(up < 0) then
- repeatMoves("d", -1 * up)
- else
- repeatMoves("u", up)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement