more communication
This commit is contained in:
parent
fcd7818649
commit
9b7ac6ff34
2 changed files with 26 additions and 4 deletions
19
bring
19
bring
|
@ -2,5 +2,24 @@ local args = { ... }
|
||||||
|
|
||||||
-- the wifi side, i guess...
|
-- the wifi side, i guess...
|
||||||
rednet.open("right");
|
rednet.open("right");
|
||||||
|
|
||||||
|
-- aks for the item
|
||||||
rednet.broadcast(args[1])
|
rednet.broadcast(args[1])
|
||||||
|
|
||||||
|
-- get ack
|
||||||
|
local id, message = rednet.receive(3)
|
||||||
|
if message == "ack" then
|
||||||
|
print("He is coming, please wait")
|
||||||
|
local id2 = nil
|
||||||
|
|
||||||
|
-- ignore other messages from others sources...
|
||||||
|
while (id ~= id2) or (message ~= "return") do
|
||||||
|
id2, message = rednet.receive()
|
||||||
|
end
|
||||||
|
|
||||||
|
print("He returned safely :)")
|
||||||
|
elseif message == "empty" then
|
||||||
|
printf("There is no " .. args[1])
|
||||||
|
else
|
||||||
|
print("No slave responded for " .. args[1])
|
||||||
|
end
|
||||||
|
|
9
slave
9
slave
|
@ -5,15 +5,18 @@ while true do
|
||||||
-- we are using wireless to get the distance
|
-- we are using wireless to get the distance
|
||||||
-- so the master should be aligned with the slaves
|
-- so the master should be aligned with the slaves
|
||||||
local id, mess, dist = rednet.receive()
|
local id, mess, dist = rednet.receive()
|
||||||
if mess == id then
|
if mess == args[1] then
|
||||||
|
rednet.send(id, "ack")
|
||||||
turtle.up()
|
turtle.up()
|
||||||
for i = 1, dist do turtle.back() end
|
for i = 1, dist do turtle.back() end
|
||||||
|
|
||||||
-- TODO: wait for empty chest or something
|
print("I will leave again in 5 seconds...")
|
||||||
sleep(1)
|
sleep(5)
|
||||||
|
print("Bye!")
|
||||||
|
|
||||||
for i = 1, dist do turtle.forward() end
|
for i = 1, dist do turtle.forward() end
|
||||||
turtle.down()
|
turtle.down()
|
||||||
|
rednet.send(id, "return")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Reference in a new issue