SHOW:
|
|
- or go back to the newest paste.
| 1 | - | local component = require("component") |
| 1 | + | local component = require("component")
|
| 2 | - | local event = require("event") |
| 2 | + | local event = require("event")
|
| 3 | - | local modem = component.modem |
| 3 | + | local modem = component.modem |
| 4 | - | modem.open(1024) |
| 4 | + | modem.open(1024) |
| 5 | - | listeners={} |
| 5 | + | listeners={}
|
| 6 | - | |
| 6 | + | |
| 7 | - | event.listen("modem_message", function(_,_,blah,_,_,_) |
| 7 | + | event.listen("modem_message", function(_,_,blah,_,_,_)
|
| 8 | - | dup = 0 |
| 8 | + | dup = 0 |
| 9 | - | for i = 1, #listeners do |
| 9 | + | for i = 1, #listeners do |
| 10 | - | if blah == listeners[i] then |
| 10 | + | if blah == listeners[i] then |
| 11 | - | dup = 1 |
| 11 | + | dup = 1 |
| 12 | - | end |
| 12 | + | end |
| 13 | - | end |
| 13 | + | end |
| 14 | - | if dup ~= 1 then |
| 14 | + | if dup ~= 1 then |
| 15 | - | table.insert(listeners, blah) |
| 15 | + | table.insert(listeners, blah) |
| 16 | - | end |
| 16 | + | end |
| 17 | - | print(blah) |
| 17 | + | print(blah) |
| 18 | - | end) |
| 18 | + | end) |
| 19 | - | |
| 19 | + | |
| 20 | - | function helloisanyonethere(port,msg) |
| 20 | + | function helloisanyonethere(port,msg) |
| 21 | - | return modem.broadcast(port,msg) |
| 21 | + | return modem.broadcast(port,msg) |
| 22 | - | end -- ¯\_(ツ)_/¯ |
| 22 | + | end -- ¯\_(ツ)_/¯ |
| 23 | - | |
| 23 | + | |
| 24 | - | |
| 24 | + | |
| 25 | - | while true do |
| 25 | + | while true do |
| 26 | - | for i = 1, #listeners do |
| 26 | + | for i = 1, #listeners do |
| 27 | - | print(listeners[i]) |
| 27 | + | print(listeners[i]) |
| 28 | - | end |
| 28 | + | end |
| 29 | - | os.sleep(1) |
| 29 | + | os.sleep(1) |
| 30 | - | --print(helloisanyonethere(1024,"ping")) |
| 30 | + | --print(helloisanyonethere(1024,"ping")) |
| 31 | end |