Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local position = vector.new(gps.locate(5))
- local home = vector.new(-265,101,8)
- local orientation = 0
- local function turnleft()
- orientation = orientation - 1
- if orientation < -1 then orientation = 2 end
- turtle.turnLeft()
- end
- local function turnright()
- orientation = orientation + 1
- if orientation > 2 then orientation = -1 end
- turtle.turnRight()
- end
- local success = true
- local function forward()
- if orientation == 0 then position.x = position.x - 1 end
- if orientation == 2 then position.x = position.x + 1 end
- if orientation == -1 then position.z = position.z - 1 end
- if orientation == 1 then position.z = position.z + 1 end
- success = turtle.forward()
- end
- local function up()
- position.y = position.y + 1
- success = turtle.up()
- end
- local funtion down()
- position.y = position.y - 1
- turtle.down()
- end
- local function gohome()
- while position.y < 120 then up() end
- while orientation < 2 then turnright() end
- while position.x < home.x then forward() end
- turnright()
- turnright()
- while position.x > home.x then forward() end
- turnright()
- while position.z < home.z then forward() end
- turnright()
- turnright()
- while position.z > home.z then forward() end
- while position.y > 101 then down() end
- turnright()
- end
- local temp = vector.new(gps.location(5))
- local function findorient()
- temp = vector.new(gps.location(5))
- if forward then
- position = vector.new(gps.location(5))
- if position.x == temp.x then
- if position.z > temp.z then orientation = 1
- else
- orientation = -1
- end
- else
- if position.x > temp.x then orientation = 2
- else
- orientation = 0
- end
- else
- up()
- end
- end
- findorient()
- gohome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement