Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gotoapi(gx, gy, gz, enddirlet)
- --local tArgs = {...}
- local face = 0
- local r = 1
- tru = 1
- local tturned = 0
- rednet.open("left")
- local cx,cy,cz = gps.locate(2,false)
- if (gx and gy and gz) == nil then
- print("Incorrect usage of Function.")
- --print("goto <x> <y> <z> (<Heading>)")
- else
- --local gx = tonumber(tArgs[1])
- --local gy = tonumber(tArgs[2])
- --local gz = tonumber(tArgs[3])
- --local enddirlet = tArgs[4]
- local x
- local y
- local z
- if enddirlet ~= nil then
- if enddirlet == "n" or enddirlet == "north" then
- enddir = 4
- end
- if enddirlet == "s" or enddirlet == "south" then
- enddir = 2
- end
- if enddirlet == "e" or enddirlet == "east" then
- enddir = 1
- end
- if enddirlet == "w" or enddirlet == "west" then
- enddir = 3
- end
- end
- function tturnup()
- tturned = tturned + 1
- if tturned > 10 then
- os.reboot()
- end
- end
- function PL()
- --print("Going to:")
- --write(gx) write(" ") write(gy) write(" ") print(gz)
- end
- function c_face()
- if face >= 5 then
- face = 1
- elseif face <= 0 then
- face = 4
- end
- end
- function get_Face()
- while turtle.forward() == false do
- tturned = 0
- if turtle.up() == false then
- --turtle.digUp()
- end
- end
- nx,ny,nz = gps.locate(3,false)
- if nx > cx then
- face = 1
- end
- if nx < cx then
- face = 3
- end
- if nz > cz then
- face = 2
- end
- if nz < cz then
- face = 4
- end
- end
- function calc()
- x = nx - gx
- y = ny - gy
- z = nz - gz
- end
- function setDir(dir)
- noredoturndir = 0
- c_face()
- if dir == 4 then
- if face == 1 then
- gototurnleft = 1
- --print("E-to-N")
- noredoturndir = 1
- end
- end
- if dir == 1 then
- if face == 4 then
- gototurnleft = 0
- --print("N-to-E")
- noredoturndir = 1
- end
- end
- if noredoturndir == 0 then
- if face >= dir then
- gototurnleft = 1
- end
- if face < dir then
- gototurnleft = 0
- end
- end
- if dir == 4 then
- if face == 1 then
- gototurnleft = 1
- --print("E-to-N")
- noredoturndir = 1
- end
- end
- if dir == 1 then
- if face == 4 then
- gototurnleft = 0
- --print("N-to-E")
- noredoturndir = 1
- end
- end
- while dir ~= face do
- c_face()
- if gototurnleft == 1 then
- turtle.turnLeft()
- face = face - 1
- tturnup()
- end
- if gototurnleft == 0 then
- turtle.turnRight()
- face = face + 1
- tturnup()
- end
- c_face()
- end
- noredoturndir = 0
- end
- function f()
- while not turtle.forward() do
- tturned = 0
- if not turtle.up() then
- --turtle.digUp()
- end
- y = y + 1
- end
- end
- function go()
- tturned = 0
- if x < 0 then
- setDir(1)
- while x ~= 0 do
- f()
- x = x + 1
- end
- end
- if x > 0 then
- setDir(3)
- while x ~= 0 do
- f()
- x = x - 1
- end
- end
- if z < 0 then
- setDir(2)
- while z ~= 0 do
- f()
- z = z + 1
- end
- end
- if z > 0 then
- setDir(4)
- while z ~= 0 do
- f()
- z = z - 1
- end
- end
- while y < 0 do
- tturned = 0
- if turtle.up() ~= true then
- --turtle.digUp()
- end
- y = y + 1
- end
- while y > 0 do
- tturned = 0
- if turtle.down() ~= true then
- --turtle.digDown()
- end
- y = y - 1
- end
- end
- tonumber(gx)
- tonumber(gy)
- tonumber(gz)
- PL()
- get_Face()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- setDir(1)
- setDir(4)
- --if enddir ~= nil then
- -- setDir(enddir)
- --end
- end
- end
- gotoapi(1, 1, 1)
- function goto(Workinggototable)
- gototable = {}
- goit = 1
- while goit < 5 do
- if Workinggototable[goit] ~= nil then
- table.insert(gototable, Workinggototable[goit])
- elseif Workinggototable[goit] == nil then
- table.insert(gototable, Workinggototable[goit])
- break
- end
- goit = goit + 1
- end
- gotoapi(gototable[1], gototable[2], gototable[3], gototable[4])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement