SHOW:
|
|
- or go back to the newest paste.
| 1 | function pack(...) | |
| 2 | retVal = {}
| |
| 3 | for i, v in ipairs(arg) do | |
| 4 | table.insert(retVal, v) | |
| 5 | end | |
| 6 | return retVal | |
| 7 | end | |
| 8 | ||
| 9 | function getAllPeripherals(filter) | |
| 10 | retVal = {}
| |
| 11 | filter = filter or false | |
| 12 | peripherals = peripheral.getNames() | |
| 13 | if not filter then | |
| 14 | return peripherals | |
| 15 | end | |
| 16 | - | monitors = pack(peripheral.find("monitor"))
|
| 16 | + | for i,v in ipairs(peripherals) do |
| 17 | if peripheral.getType(v) == filter then | |
| 18 | table.insert(retVal, peripheral.wrap(v)) | |
| 19 | end | |
| 20 | end | |
| 21 | return retVal | |
| 22 | end | |
| 23 | ||
| 24 | function writeToMonitors(monitors, word) | |
| 25 | for i, v in ipairs(monitors) do | |
| 26 | v.setCursorPos(1,1) | |
| 27 | v.write(word) | |
| 28 | end | |
| 29 | end | |
| 30 | ||
| 31 | monitors = getAllPeripherals("monitor")
| |
| 32 | ||
| 33 | writeToMonitors(monitors, "Hello, World!") |