Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- position = split(getPos())
- x = tonumber(position[1])
- y = tonumber(position[2])
- z = tonumber(position[3])
- f = tonumber(position[4])
- m_table = {
- ["fd"] = function()
- if(turtle.forward()) then
- if (f == 1) then
- z = z+1
- elseif (f == 2) then
- x = x+1
- elseif (f == 3) then
- z = z-1
- elseif (f == 4) then
- x = x-1
- end
- return true
- else return false end
- end,
- ["bk"] = function()
- if(turtle.back()) then
- if (f == 1) then
- z = z-1
- elseif (f == 2) then
- x = x-1
- elseif (f == 3) then
- z = z+1
- elseif (f == 4) then
- x = x+1
- end
- return true
- else return false end
- end,
- ["rt"] = function()
- if(turtle.turnRight()) then
- if (f < 4) then
- f = f+1
- else
- f = 1
- end
- return true
- else return false end
- end,
- ["lt"] = function()
- if(turtle.turnLeft()) then
- if (f > 1) then
- f = f-1
- else
- f = 4
- end
- return true
- else return false end
- end,
- ["up"] = function()
- if(turtle.up()) then
- y = y + 1
- return true
- else return false end
- end,
- ["dn"] = function()
- if(turtle.down()) then
- y = y - 1
- return true
- else
- return false
- end
- end
- }
- function move(direction)
- local _move = m_table[direction]
- if (_move) then
- if _move() then
- setPos(x,y,z,f)
- return true
- else
- return false
- end
- end
- end
- function moveF(destination)
- destination = tonumber(destination)
- path = {}
- if getFPos() == destination then return end
- repeat
- if getFPos() % destination == 1 then
- move("lt")
- table.insert(path,"lt")
- else
- move("rt")
- table.insert(path,"rt")
- end
- until getFPos() == destination
- return path
- end
- function moveY(destination)
- destination = tonumber(destination)
- if getYPos() == destination then return end
- if (getYPos() < destination) then
- repeat
- if not move("up") then
- return
- end
- until getYPos() == destination
- elseif (getYPos() > destination) then
- repeat
- if not move("dn") then
- return
- end
- until getYPos() == destination
- end
- end
- function moveT(instructions)
- if type(instructions) ~= "table" then return false end
- for k,v in pairs(instructions) do
- move(v)
- end
- end
- function inversePath(path)
- if type(path) ~= "table" then return end
- for k,v in pairs(path) do
- if path[k] == "fd" then
- path[k] = "bk"
- elseif path[k] == "bk" then
- path[k] = "fd"
- elseif path[k] == "rt" then
- path[k] = "lt"
- elseif path[k] == "lt" then
- path[k] = "rt"
- end
- end
- return path
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement