Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x = 0
- y = 0
- z = 0
- dir = 0
- -- check fuel
- function fuel()
- if turtle.getFuelLevel() <= 100 then
- turtle.select(16)
- turtle.refuel(1)
- print("Refueled. Fuel level is :".. turtle.getFuelLevel())
- end
- end
- -- up
- function up()
- fuel()
- if turtle.up() then
- return true
- end
- return false
- end
- -- down
- function dn()
- fuel()
- if turtle.down() then
- return true
- end
- return false
- end
- -- turnLeft
- function lt()
- if turtle.turnLeft() then
- dir = dir - 1
- if dir < 0 then
- dir = 3
- end
- return true
- end
- return false
- end
- -- turnRight
- function rt()
- if turtle.turnRight() then
- dir = dir + 1
- if dir > 3 then
- dir = 0
- end
- return true
- end
- return false
- end
- -- forward
- function fd()
- fuel()
- if turtle.forward() then
- changePos("fd")
- return true
- end
- return false
- end
- -- back
- function bk()
- fuel()
- if turtle.back() then
- changePos("bk")
- return true
- end
- return false
- end
- -- get location by gps
- function gpsUpdate()
- x, y, z = gps.locate(5)
- if x == nil then
- return false
- end
- return true
- end
- -- direction
- function checkDir()
- turtle.forward()
- turtle.forward()
- cx, cy, cz = gps.locate(1)
- if (x - cx) == 2 then
- print("W")
- dir = 3
- end
- if (z - cz) == 2 then
- print("N")
- dir = 0
- end
- if (x - cx) == -2 then
- print("E")
- dir = 1
- end
- if (z - cz) == -2 then
- print("S")
- dir = 2
- end
- turtle.back()
- turtle.back()
- end
- function getDir()
- print(dir)
- end
- -- change pos
- function changePos(command)
- if command == "fd" then
- if dir == 0 then
- z = z - 1
- end
- if dir == 1 then
- x = x + 1
- end
- if dir == 2 then
- z = z + 1
- end
- if dir == 3 then
- x = x - 1
- end
- end
- if command == "bk" then
- if dir == 0 then
- z = z + 1
- end
- if dir == 1 then
- x = x - 1
- end
- if dir == 2 then
- z = z - 1
- end
- if dir == 3 then
- x = x + 1
- end
- end
- end
- -- get positions
- function getPos()
- print(x..","..y..","..z)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement