Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle Self-tracking System created by Arclight306
- local xPos, yPos, zPos = nil
- local face = nil
- local cal = false
- function gpsLocation(facing) -- get gps using other computers
- xPos, yPos, zPos = gps.locate()
- if xPos == nil then
- cal = false
- return false
- else
- if facing == "north" or facing == "east" or facing == "south" or facing == "west" then
- face = facing
- cal = true
- return true
- else
- cal=false
- assert(false, "Facing must be north, south, east or west")
- end
- return false
- end
- end
- function manSetLocation(x, y, z, facing) -- manually set location
- assert(type(x) == "number", "x must be a number")
- assert(type(y) == "number", "y must be a number")
- assert(type(z) == "number", "z must be a number")
- if facing == "north" or facing == "east" or facing == "south" or facing == "west" then
- face = facing
- cal = true
- else
- cal=false
- assert(false, "Facing must be north, south, east or west")
- end
- xPos = x
- yPos = y
- zPos = z
- face = facing
- end
- function getLocation() -- return the location
- if xPos ~= nil then
- return xPos, yPos, zPos, face
- elseif xPos == nil then
- return nil
- end
- end
- function turnLeft() -- turn left
- if(turtle.turnLeft()) then
- if face == "north" then
- face = "west"
- elseif face == "west" then
- face = "south"
- elseif face == "south" then
- face = "east"
- elseif face == "east" then
- face = "north"
- end
- return true
- end
- return false
- end
- function turnRight() -- turn right
- if(turtle.turnRight()) then
- if face == "north" then
- face = "east"
- elseif face == "east" then
- face = "south"
- elseif face == "south" then
- face = "west"
- elseif face == "west" then
- face = "north"
- end
- return true
- end
- return false
- end
- function forward() -- go forward
- if(turtle.forward()) then
- if cal == true then
- if face == "north" then
- zPos = zPos - 1
- elseif face == "west" then
- xPos = xPos - 1
- elseif face == "south" then
- zPos = zPos + 1
- elseif face == "east" then
- xPos = xPos + 1
- end
- else
- print("Not Calibrated.")
- end
- return true
- end
- return false
- end
- function back() -- go back
- if(turtle.back()) then
- if cal == true then
- if face == "north" then
- zPos = zPos + 1
- elseif face == "west" then
- xPos = xPos + 1
- elseif face == "south" then
- zPos = zPos - 1
- elseif face == "east" then
- xPos = xPos - 1
- end
- else
- print("Not Calibrated.")
- end
- return true
- else
- return false
- end
- end
- function up() -- go up
- if(turtle.up()) then
- if cal == true then
- yPos = yPos + 1
- else
- print("Not Calibrated.")
- end
- return true
- else
- return false
- end
- end
- function down() -- go down
- if(turtle.down()) then
- if cal == true then
- yPos = yPos - 1
- else
- print("Not Calibrated.")
- end
- return true
- else
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement