Lua scripts for the computercraft mod for minecraft
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

38 lines
918 B

-- Master of the automatic bringing system
-- Works with a simple protocol:
-- Master: broadcast -item-
-- matching slave: send -ack- or -empty-
-- in case of a -ack- the master will wait for -return-
-- in case of -empty- the master will exit
-- if there is no matching slave, then the master won't receive ack and exits
-- if there are more matching slaves, then there is UB
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
print("There is no " .. args[1])
else
print("No slave responded for " .. args[1])
end