Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function receive()
- while(true) do
- local id, msg = rednet.receive()
- print(msg)
- end
- end
- function main()
- local msg = abc
- startx,starty,startz=gps.locate()
- x,y,z = gps.locate()
- term.clear()
- term.setCursorPos(1,1)
- rednet.open("right")
- rednet.broadcast("Robo01 connected")
- print("please open 'online' on your other pocket device.")
- print("press enter to begin")
- io.read()
- function sendcoords()
- x,y,z = gps.locate()
- rednet.broadcast("Robo01: "..x.. " " ..y.. " " ..z)
- end
- function home()
- rednet.broadcast("Robo01 returning home")
- endx,endy,endz = gps.locate(10)
- end1 = true
- while(end1)
- do
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- x,y,z = gps.locate()
- sendcoords()
- disendx = startx - endx
- if disendx < 0
- then
- disendx = disendx * -1
- end
- discurx = startx - x
- if discurx < 0
- then
- discurx = discurx * -1
- end
- if disendx > discurx
- then
- end1 = false
- end
- turtle.back()
- end
- end2 = true
- while(end2)
- do
- turtle.dig()
- turtle.forward()
- x,y,z = gps.locate()
- sendcoords()
- discurx = startx - x
- if discurx < 0
- then
- discurx = discurx * -1
- end
- if discurx == 0
- then
- end2 = false
- end
- end
- end3 = true
- while(end3)
- do
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- x,y,z = gps.locate()
- sendcoords()
- disendz = startz - endz
- if disendz < 0
- then
- disendz = disendz * -1
- end
- discurz = startz - z
- if discurz < 0
- then
- discurz = discurz * -1
- end
- if disendz > discurz
- then
- end3 = false
- end
- turtle.back()
- end
- end4 = true
- while(end4)
- do
- turtle.dig()
- turtle.forward()
- x,y,z = gps.locate()
- sendcoords()
- discurz = startz - z
- if discurz < 0
- then
- discurz = discurz * -1
- end
- if discurz == 0
- then
- end4 = false
- end
- end
- end5 = true
- while(end5)
- do
- turtle.digUp()
- turtle.up()
- x,y,z = gps.locate()
- sendcoords()
- if y == starty
- then
- end5 = false
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- end
- while(y > 12)
- do
- turtle.digDown()
- turtle.down()
- x,y,z = gps.locate()
- sendcoords()
- end
- mine = true
- while(mine)
- do
- if mine == true
- then
- turn = math.random(1,3)
- rnd = math.random(20,100)
- end
- while(rnd > 0)
- do
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- turtle.digUp()
- sendcoords()
- rnd = rnd - 1
- slot = turtle.getItemCount(16)
- if slot > 0
- then
- rnd = 0
- mine = false
- turn = 0
- end
- if msg == "home"
- then
- rnd = 0
- mine = false
- turn = 0
- end
- end
- if turn == 1
- then
- turtle.turnRight()
- elseif turn > 1
- then
- turtle.turnLeft()
- end
- end
- home()
- end
- parallel.waitForAll(receive,main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement