Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function forward()
- file = io.open("tortoiseDir","r")
- direction = file:read()
- file:close()
- file = io.open("tortoiseX","r")
- x = file:read()
- file:close()
- file = io.open("tortoiseY","r")
- y = file:read()
- file:close()
- file = io.open("tortoiseZ","r")
- z = file:read()
- file:close()
- lawl = turtle.forward()
- if lawl == true then
- if direction == "north" then
- fs.delete("tortoiseZ")
- file = io.open("tortoiseZ","w")
- z = tonumber(z)
- file:write(z-1)
- file:close()
- end
- if direction == "west" then
- fs.delete("tortoiseX")
- file = io.open("tortoiseX","w")
- x = tonumber(x)
- file:write(x-1)
- file:close()
- end
- if direction == "south" then
- fs.delete("tortoiseZ")
- file = io.open("tortoiseZ","w")
- z = tonumber(z)
- file:write(z+1)
- file:close()
- end
- if direction == "east" then
- fs.delete("tortoiseX")
- file = io.open("tortoiseX","w")
- x = tonumber(x)
- file:write(x+1)
- file:close()
- end
- end
- end
- function getXYZD()
- file = io.open("tortoiseDir","r")
- direction = file:read()
- file:close()
- file = io.open("tortoiseX","r")
- x = tonumber(file:read())
- file:close()
- file = io.open("tortoiseY","r")
- y = tonumber(file:read())
- file:close()
- file = io.open("tortoiseZ","r")
- z = tonumber(file:read())
- file:close()
- return x,y,z,direction
- end
- function printXYZD()
- file = io.open("tortoiseDir","r")
- direction = file:read()
- file:close()
- file = io.open("tortoiseX","r")
- x = tonumber(file:read())
- file:close()
- file = io.open("tortoiseY","r")
- y = tonumber(file:read())
- file:close()
- file = io.open("tortoiseZ","r")
- z = tonumber(file:read())
- file:close()
- print(x.." "..y.." "..z.." "..direction)
- end
- function up()
- file = io.open("tortoiseY","r")
- y = file:read()
- y = tonumber(y)
- file:close()
- lawl = turtle.up()
- if lawl == true then
- fs.delete("tortoiseY")
- file = io.open("tortoiseY","w")
- if y < 126 and y >= 1 then
- file:write(y+1)
- else
- file = io.open("tortoiseY","w")
- file:write(y)
- end
- file:close()
- end
- end
- function turnLeft()
- file = io.open("tortoiseDir","r")
- direction = file:read()
- file:close()
- fs.delete("tortoiseDir")
- turtle.turnLeft()
- file = io.open("tortoiseDir","w")
- if direction == "west" then
- file:write("south")
- end
- if direction == "east" then
- file:write("north")
- end
- if direction == "south" then
- file:write("east")
- end
- if direction == "north" then
- file:write("west")
- end
- file:close()
- end
- function turnRight()
- file = io.open("tortoiseDir","r")
- direction = file:read()
- file:close()
- fs.delete("tortoiseDir")
- turtle.turnRight()
- file = io.open("tortoiseDir","w")
- if direction == "west" then
- file:write("north")
- end
- if direction == "east" then
- file:write("south")
- end
- if direction == "south" then
- file:write("west")
- end
- if direction == "north" then
- file:write("east")
- end
- file:close()
- end
- function setup()
- term.clear()
- term.setCursorPos( 1, 1 )
- print("What direction is your turtle currently facing? (lower case)")
- out = read()
- file = io.open("tortoiseDir","w")
- file:write(out)
- file:close()
- print("Current X Coord?")
- out = read()
- file = io.open("tortoiseX","w")
- file:write(out)
- file:close()
- print("Current Z Coord?")
- out = read()
- file = io.open("tortoiseZ","w")
- file:write(out)
- file:close()
- print("Current Y Coord?")
- out = read()
- file = io.open("tortoiseY","w")
- file:write(out)
- file:close()
- term.clear()
- term.setCursorPos( 1, 1 )
- print("Finished")
- end
- function down()
- file = io.open("tortoiseY","r")
- y = file:read()
- y = tonumber(y)
- file:close()
- lawl = turtle.down()
- fs.delete("tortoiseY")
- if lawl == true then
- file = io.open("tortoiseY","w")
- if y <= 126 and y > 1 then
- file:write(y-1)
- end
- else
- file = io.open("tortoiseY","w")
- file:write(y)
- end
- file:close()
- end
- function goto(x,y,z)
- xx,yy,zz,dd = tortoise.getXYZD()
- if yy < y then
- for i = 1,math.abs(yy-y) do
- tortoise.up()
- end
- elseif yy > y then
- for i = 1,math.abs(y-yy) do
- tortoise.down()
- end
- end
- if xx < x then
- for i = 1,4 do
- lol,lol,lol,dd = tortoise.getXYZD()
- if dd ~= "east" then
- tortoise.turnLeft()
- end
- end
- for i = 1,math.abs(xx-x) do
- tortoise.forward()
- end
- elseif xx > x then
- for i = 1,4 do
- lol,lol,lol,dd = tortoise.getXYZD()
- if dd ~= "west" then
- tortoise.turnRight()
- end
- end
- for i = 1,math.abs(x-xx) do
- tortoise.forward()
- end
- end
- if zz < z then
- for i = 1,4 do
- lol,lol,lol,dd = tortoise.getXYZD()
- if dd ~= "south" then
- tortoise.turnLeft()
- end
- end
- for i = 1,math.abs(zz-z) do
- tortoise.forward()
- end
- elseif zz > z then
- for i = 1,4 do
- lol,lol,lol,dd = tortoise.getXYZD()
- if dd ~= "north" then
- tortoise.turnRight()
- end
- end
- for i = 1,math.abs(z-zz) do
- tortoise.forward()
- end
- end
- xx,yy,zz,dd = tortoise.getXYZD()
- if xx ~= x or yy ~= y or zz ~= z then
- print("Obstructed during flight.")
- return false
- else
- return true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement