Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bot = {}
- local function savePos()
- local handle = fs.open("enderMine/savedFile", "w")
- handle.write(textutils.serialize(bot))
- handle.close()
- end
- local function loadPos()
- local files = fs.list("/rom/enderMine")
- for i = 1, #files do
- print(files[i])
- end
- if fs.exists(filename) == true then
- local handle = fs.open("enderMine/savedFile", "r")
- readFile = handle.readLine()
- if readFile ~= nil then
- bot = textutils.unserialize(readFile)
- end
- handle.close()
- else
- print("file does not exist, check path..")
- end
- end
- local function printPos()
- term.clear()
- term.setCursorPos(1,1)
- print("------------")
- print("x"..bot.currX)
- print("z"..bot.currZ)
- print("y"..bot.currY)
- print("direction "..bot.direction)
- print("layer "..bot.currLayer)
- print("------------")
- end
- local function moveForward()
- while not turtle.forward() do
- turtle.dig()
- end
- savePos()
- printPos()
- end
- local function moveUp()
- while not turtle.up() do
- turtle.digUp()
- end
- bot.currY = bot.currY+1
- savePos()
- printPos()
- end
- local function moveDown()
- while not turtle.down() do
- turtle.digDown()
- end
- bot.currY = bot.currY-1
- savePos()
- printPos()
- end
- local function turnRight()
- turtle.turnRight()
- bot.direction = bot.direction +1
- if bot.direction > 4 then
- bot.direction = 1
- end
- savePos()
- printPos()
- end
- local function turnLeft()
- turtle.turnLeft()
- bot.direction = bot.direction -1
- if bot.direction < 1 then
- bot.direction = 4
- end
- savePos()
- printPos()
- end
- local function gotoShaft() -- finder punktet hvor den gik ned "skakten"
- while bot.direction ~= 3 do
- turnRight()
- end
- while bot.currX > 1 do
- moveForward()
- bot.currX = bot.currX -1
- savePos()
- end
- while bot.direction ~= 4 do
- turnRight()
- end
- while bot.currZ > 1 do
- moveForward()
- bot.currZ = bot.currZ -1
- savePos()
- end
- while bot.direction ~= 1 do
- turnRight()
- end
- end
- local function toSurface()
- while tonumber(bot.currY) < tonumber(bot.yStart) do
- moveUp()
- end
- end
- loadPos()
- gotoShaft()
- toSurface()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement