Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local link = ""
- function forward(num)
- num = num or 1
- for i = 1, num do
- if turtle.forward() then
- if f == 0 then
- z = z - 1
- updatePos()
- elseif f == 1 then
- x = x + 1
- updatePos()
- elseif f == 2 then
- z = z + 1
- updatePos()
- elseif f == 3 then
- x = x - 1
- updatePos()
- end
- checkFuel(returning)
- else
- return false
- end
- end
- return true
- end
- function back(num)
- num = num or 1
- for i = 1, num do
- if turtle.back() then
- if f == 0 then
- z = z + 1
- updatePos()
- elseif f == 1 then
- x = x - 1
- updatePos()
- elseif f == 2 then
- z = z - 1
- updatePos()
- elseif f == 3 then
- x = x + 1
- updatePos()
- end
- checkFuel(returning)
- else
- return false
- end
- end
- return true
- end
- function up(num)
- num = num or 1
- for i = 1, num do
- if turtle.up() then
- y = y + 1
- updatePos()
- checkFuel(returning)
- else
- return false
- end
- end
- return true
- end
- function down(num)
- num = num or 1
- for i = 1, num do
- if turtle.down() then
- y = y - 1
- updatePos()
- checkFuel(returning)
- else
- return false
- end
- end
- return true
- end
- function left(num)
- num = num or 1
- for i = 1, num do
- turtle.turnLeft()
- f = (f+3)%4
- updatePos()
- end
- end
- function right(num)
- num = num or 1
- for i = 1, num do
- turtle.turnRight()
- f = (f+1)%4
- updatePos()
- end
- end
- function updatePos()
- local str = fs.open("info","r").readAll()
- str = str:gsub("x%=%d;","x="..x..";")
- str = str:gsub("y%=%d;","y="..y..";")
- str = str:gsub("z%=%d;","z="..z..";")
- str = str:gsub("f%=%d;","f="..f..";")
- local h = fs.open("info","w")
- h.write(str)
- h.close()
- end
- -- 0 (-z)
- -- 3 (-x) 1 (+x)
- -- 2 (+z)
- function home()
- returning = true
- while y ~= 0 do
- if y < 0 then
- turtle.digUp()
- up()
- elseif y > 0 then
- turtle.digDown()
- down()
- end
- end
- if z > 0 then
- while f ~= 0 do
- left()
- end
- elseif z < 0 then
- while f ~= 2 do
- left()
- end
- end
- while z ~= 0 do
- forward()
- end
- if x > 0 then
- while f ~= 3 do
- left()
- end
- elseif x < 0 then
- while f ~= 1 do
- left()
- end
- end
- while x ~= 0 do
- forward()
- end
- end
- shell.run("info")
- shell.run("pastebin run " .. link)
- home()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement