Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local direction = tArgs[1]
- local times = tonumber(tArgs[2])
- if not turtle then
- error("You need a turtle!")
- end
- if times == nil then
- times = 1
- end
- local possibleDirections = {"left","right","up","down","forward","back"}
- local translateDirection = {"turnLeft","turnRight","up","down","forward","back"}
- if #tArgs < 1 then
- print("Usage:")
- print(shell.getRunningProgram().." <direction> (times)")
- print("Parameters:")
- print("<> = required")
- print("() = optional")
- return false
- end
- local function go(aDirection,aTimes,detect)
- print("Going "..direction.." for "..times.." blocks")
- if detect == nil then
- local detect = "detectUp"
- for i=1,aTimes do
- turtle[aDirection]()
- end
- elseif detect ~= nil then
- for i=1,aTimes do
- if turtle[detect]() == false then
- turtle[aDirection]()
- else
- print("Something in the way!")
- return false
- end
- end
- end
- end
- for i=1,#possibleDirections do
- if direction == possibleDirections[i] then
- if direction == "forward" then detectIt = "detect"
- elseif direction == "up" then detectIt = "detectUp"
- elseif direction == "down" then detectIt = "detectDown"
- else detectIt = nil
- end
- if go(translateDirection[i],times,detectIt) == true then
- return true
- else
- return false
- end
- end
- end
- print("Invalid Direction")
- print("Possible Directions:")
- for i=1,#possibleDirections do
- print(possibleDirections[i])
- end
- return false
Advertisement
Add Comment
Please, Sign In to add comment