Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local xPos, yPos, zPos = nil
- face = nil
- cal = false
- function setLocation() -- get gps using other computers
- xPos, yPos, zPos = gps.locate()
- if turtle.forward() then
- nxPos, nyPos, nzPos = gps.locate()
- end
- turtle.back()
- if zPos > nzPos then --if north
- face = 0
- end
- if xPos < nxPos then --if east
- face = 3
- end
- if zPos < nzPos then --if south
- face = 2
- end
- if xPos > nxPos then --if west
- face = 1
- end
- cal = true
- end
- function manSetLocation(x, y, z, f) -- manually set location
- xPos = x
- yPos = y
- zPos = z
- face = f
- cal = true
- end
- function getLocation() -- return the location
- if xPos ~= nil then
- return xPos, yPos, zPos, face
- else
- return nil
- end
- end
- function turnLeft() -- turn left
- if turtle.turnLeft() then
- if face == 0 then
- face = 1
- elseif face == 1 then
- face = 2
- elseif face == 2 then
- face = 3
- elseif face == 3 then
- face = 0
- end
- end
- end
- function turnRight() -- turn right
- if turtle.turnRight() then
- if face == 0 then
- face = 3
- elseif face == 1 then
- face = 0
- elseif face == 2 then
- face = 1
- elseif face == 3 then
- face = 2
- end
- end
- end
- function forward() -- go forward
- if turtle.forward() then
- if cal == true then
- if face == 0 then
- zPos = zPos - 1
- elseif face == 1 then
- xPos = xPos - 1
- elseif face == 2 then
- zPos = zPos + 1
- elseif face == 3 then
- xPos = xPos + 1
- end
- else
- print("Not Calibrated.")
- end
- end
- end
- function back() -- go back
- if turtle.back() then
- if cal == true then
- if face == 0 then
- zPos = zPos + 1
- elseif face == 1 then
- xPos = xPos + 1
- elseif face == 2 then
- zPos = zPos - 1
- elseif face == 2 then
- xPos = xPos - 1
- end
- else
- print("Not Calibrated.")
- end
- end
- end
- function up() -- go up
- turtle.up()
- if cal == true then
- yPos = yPos + 1
- else
- print("Not Calibrated.")
- end
- end
- function down() -- go down
- turtle.down()
- if cal == true then
- yPos = yPos - 1
- else
- print("Not Calibrated.")
- end
- end
- function saveData(l)
- if not fs.isDir(l) then
- local f = fs.open(l,"a")
- if cal ~= false then
- f.writeLine("Current location: "..xPos..", "..yPos..", "..zPos..", Face:"..face)
- else
- if gps.locate() then
- x,y,z = gps.locate()
- f.writeLine("Current location: "..x..", "..y..", "..z..", Face: N/A")
- else
- error("location unknown")
- end
- f.close()
- end
- else
- print("Dir With that name already exists")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement