slaves work nicely now
This commit is contained in:
parent
9b7ac6ff34
commit
75f55e6d38
2 changed files with 44 additions and 13 deletions
2
bring
2
bring
|
@ -19,7 +19,7 @@ if message == "ack" then
|
|||
|
||||
print("He returned safely :)")
|
||||
elseif message == "empty" then
|
||||
printf("There is no " .. args[1])
|
||||
print("There is no " .. args[1])
|
||||
else
|
||||
print("No slave responded for " .. args[1])
|
||||
end
|
||||
|
|
39
slave
39
slave
|
@ -1,24 +1,55 @@
|
|||
local args = { ... }
|
||||
local threshold = 5
|
||||
|
||||
local function count_total()
|
||||
local c = 0
|
||||
for i = 1, 9 do c = c + turtle.getItemCount(i) end
|
||||
return c
|
||||
end
|
||||
|
||||
local function count_space()
|
||||
local c = 0
|
||||
for i = 1, 9 do c = c + turtle.getItemSpace(i) end
|
||||
return c
|
||||
end
|
||||
|
||||
rednet.open("right")
|
||||
while true do
|
||||
-- we are using wireless to get the distance
|
||||
-- so the master should be aligned with the slaves
|
||||
local id, mess, dist = rednet.receive()
|
||||
local id, mess, dist = rednet.receive(1)
|
||||
if mess == args[1] then
|
||||
if count_total() < threshold then
|
||||
rednet.send(id, "empty")
|
||||
else
|
||||
rednet.send(id, "ack")
|
||||
|
||||
-- Wait for the pipes to be empty (and not leak)
|
||||
rs.setOutput("left", false)
|
||||
sleep(1)
|
||||
|
||||
-- GO!!!
|
||||
turtle.up()
|
||||
for i = 1, dist do turtle.back() end
|
||||
for i = 1, dist do turtle.forward() end
|
||||
|
||||
print("I will leave again in 5 seconds...")
|
||||
sleep(5)
|
||||
print("Bye!")
|
||||
|
||||
for i = 1, dist do turtle.forward() end
|
||||
for i = 1, dist do turtle.back() end
|
||||
turtle.down()
|
||||
rednet.send(id, "return")
|
||||
print("Back home :)")
|
||||
end
|
||||
end
|
||||
|
||||
-- TODO: activate redstone for the buildcraft engine
|
||||
-- This will power the engine next to the turtle
|
||||
-- We don't want to fill if we're full
|
||||
-- NOTE: we can't use the side of the modem...
|
||||
if count_space() > threshold then
|
||||
rs.setOutput("left", true)
|
||||
else
|
||||
rs.setOutput("left", false)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Reference in a new issue