For the sake of variety, here is my take on this:
Spoiler
function mine()
rednet.broadcast("mine") -- broadcast to all turts in range
x = 0
while x < 16 do -- when all turtles are done, they send "done"; count and exit when we get enough of these msgs
id, msg = rednet.receive()
if id > 0 and id < 17 and msg == "done" then -- controller runs on 0, turtles are 1-16.
x = x + 1
end
end
if DEBUG == 1 then print(x," turtles report complete") end -- extra info printed to screen on request
end
This makes it significantly faster and IMO more reliable than just having a general timer on the controller, as it just has to wait until it receives all the msgs from the turtles. That leaves the next time waster in the program on the turtles, so for that I set this up:
Spoiler
-- define the controller ID here
BOSS = 0
-- print extra msgs if enabled
DEBUG = 0
-- place the mining well in front of us
function dropMW()
if turtle.getItemCount(1) == 0 then
print("Error: Place Mining Well in Slot 1.")
else
turtle.select(1)
turtle.place()
end
end
-- speedily clear inventory
function clearInv()
if DEBUG then print("clearing inventory") end
for i = 1,10 do
turtle.select(i)
turtle.dropDown()
end
turtle.select(1)
end
-- are there items in my inventory?
function checkInv()
if DEBUG then print("checking inventory") end
for i = 1,16 do
if turtle.getItemCount(i) > 0 then
return true
end
end
turtle.select(1)
if DEBUG then print("inventory cleared") end
return false
end
-- fetch Mining Well
function getMW()
turtle.select(1)
turtle.dig()
end
------- main()
-- drop the MW so we can scar the earth
dropMW()
sleep(1)
-- dynamically check the inventory, and clear it automatically when items are detected
while checkInv() do
clearInv()
end
-- nab the MW and tell the boss we are done
getMW()
rednet.send(BOSS,"done")
I'm not going to claim that it is perfect, there are a few optimizations that could still be done, but i think it works rather nicely as it is.
A few notes: the quarry controller runs on #0, whereas the turtles are #s 1-16. The turtles are set to basically execute directly in the shell the command they receive via broadcast, which is why it is imperative to add in security, as simple as ID checking is sufficient for my purposes. This makes it nice, as once I update the code on my server terminal, I can remotely copy updates to all the folders and tell them to reboot if necessary via the controller.
Like any piece of code, there are only a billion and a half different ways one could go about doing it.