Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function forward(num)
- num = num or 1
- for i = 1, num do
- if turtle.forward() then
- if f == 0 then
- z = z - 1
- update("z",z)
- elseif f == 1 then
- x = x + 1
- update("x",x)
- elseif f == 2 then
- z = z + 1
- update("z",z)
- elseif f == 3 then
- x = x - 1
- update("x",x)
- 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
- update("z",z)
- elseif f == 1 then
- x = x - 1
- update("x",x)
- elseif f == 2 then
- z = z - 1
- update("z",z)
- elseif f == 3 then
- x = x + 1
- update("x",x)
- 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
- update("y",y)
- 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
- update("y",y)
- checkFuel(returning)
- return true
- 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
- update("f",f)
- end
- end
- function right(num)
- num = num or 1
- for i = 1, num do
- turtle.turnRight()
- f = (f+1)%4
- update("f",f)
- end
- end
- function update(var,value)
- if not tostring(var) then
- error("var needs to be a string")
- end
- value = tostring(value)
- local str = fs.open("info","r").readAll()
- if str:find(var) then
- str = str:gsub(var.."%=.-%;",var.."="..value..";")
- else
- str = str .."\n"..var.."="..value..";"
- end
- 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")
- home()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement