Advertisement
Oeed

Whereis

Jul 30th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. local WHEREIS_CHANNEL = 420
  2. local WHEREIS_REPLY_CHANNEL = 421
  3.  
  4. local modem = peripheral.find("modem")
  5. print("Finding turtles...")
  6. modem.open(WHEREIS_CHANNEL)
  7. modem.open(WHEREIS_REPLY_CHANNEL)
  8. modem.transmit(WHEREIS_CHANNEL, WHEREIS_REPLY_CHANNEL, "WHEREIS")
  9.  
  10. local found = {}
  11. parallel.waitForAny(function()
  12.     while true do
  13.         local event, side, channel, replyChannel, message = os.pullEvent("modem_message")
  14.         if channel == WHEREIS_REPLY_CHANNEL then
  15.             table.insert(found, message)
  16.             print("Found '" .. message[2] .. "' (" .. message[1] .. ") at " .. tostring(message[3]) .. ", " .. tostring(message[4]) .. ", " .. tostring(message[5]))
  17.         end
  18.     end
  19. end, function()
  20.     sleep(2.3)
  21. end)
  22. local h = fs.open("log", "w")
  23. h.write(textutils.serialise(found))
  24. h.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement