Browse Source

more communication

master
Joshua Moerman 12 years ago
parent
commit
9b7ac6ff34
  1. 19
      bring
  2. 11
      slave

19
bring

@ -2,5 +2,24 @@ local args = { ... }
-- the wifi side, i guess...
rednet.open("right");
-- aks for the item
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

11
slave

@ -5,15 +5,18 @@ 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()
if mess == id then
if mess == args[1] then
rednet.send(id, "ack")
turtle.up()
for i = 1, dist do turtle.back() end
-- TODO: wait for empty chest or something
sleep(1)
print("I will leave again in 5 seconds...")
sleep(5)
print("Bye!")
for i = 1, dist do turtle.forward() end
turtle.down()
rednet.send(id, "return")
end
end