Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function go(side,distance)
- for i=1, distance do
- if side=="up" then turtle.up() end
- if side=="down" then turtle.down() end
- if side=="forward" then turtle.forward() end
- if side=="back" then turtle.back() end
- end
- end
- function goTo(x,y,z)
- c=peripheral.wrap("left")
- myX,myZ,myY=gps.locate()
- side=c.getFacing()
- if myX==nil then
- print("no gps found :(")
- end
- divX=x-myX
- divY=y-myY
- divZ=z-myZ
- print("divX "..divX)
- print("divY "..divY)
- print("divZ "..divZ)
- if side==0 then if divZ>=1 then shell.run("go forward "..tostring(divZ)) else shell.run("go back "..tostring(math.sqrt(divZ*divZ))) end end
- if side==2 then if divZ>=1 then shell.run("go back "..tostring(divZ)) else shell.run("go forward "..tostring(math.sqrt(divZ*divZ))) end end
- if side==3 then if divX>=1 then shell.run("go forward "..tostring(divX)) else shell.run("go back "..tostring(math.sqrt(divX*divX))) end end
- if side==1 then if divX>=1 then shell.run("go back "..tostring(divX)) else shell.run("go forward "..tostring(math.sqrt(divX*divX))) end end
- turtle.turnLeft()
- side=c.getFacing()
- if side==0 then if divZ>=1 then shell.run("go forward "..tostring(divZ)) else shell.run("go back "..tostring(math.sqrt(divZ*divZ))) end end
- if side==2 then if divZ>=1 then shell.run("go back "..tostring(divZ)) else shell.run("go forward "..tostring(math.sqrt(divZ*divZ))) end end
- if side==3 then if divX>=1 then shell.run("go forward "..tostring(divX)) else shell.run("go back "..tostring(math.sqrt(divX*divX))) end end
- if side==1 then if divX>=1 then shell.run("go back "..tostring(divX)) else shell.run("go forward "..tostring(math.sqrt(divX*divX))) end end
- if divY>=1 then shell.run("go up "..tostring(divY)) else shell.run("go down "..tostring(math.sqrt(divY*divY))) end
- end
- args = {...}
- x=args[1]
- y=args[2]
- z=args[3]
- if args~=nil then
- goTo(x,y,z)
- end
Add Comment
Please, Sign In to add comment