This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Kingdaro's profile picture

NetGroup - Network peripherals made easy.

Started by Kingdaro, 16 March 2013 - 02:38 PM
Kingdaro #1
Posted 16 March 2013 - 03:38 PM
About
NetGroup, put simply, is a nice, simple API that allows you to use multiple peripherals and multiple peripheral types over wired cables with ease. You can mass-print, project across many monitors, and turn on or turn off many computers with a couple commands.

Usage / Tutorial

-- Get a group object
-- Arguments are the modem side and the peripheral filter (e.g. "monitor", "printer", "computer")
group = netgroup.wrap('back', 'printer')

-- Use the object like a normal peripheral
group.newPage()
group.setPageTitle('This is a page title!')
group.write('Some text!')
group.endPage()

-- Set the groups filter to another object
group.filter('monitor')

-- Can use the same function to get the current filter
print(group.filter()) --> monitor

-- Dynamic arguments based on monitor/peripheral name
-- Functions receive the monitor and peripheral name
group.setCursorPos(function(mon) -- centered text
  local w,h = mon.getSize()
  return w/2, h/2
end)
group.setBackgroundColor(colors.black)
group.setTextColor(function() return 2^math.random(14) end) -- random text color
group.clear()
group.write(function(mon, name) return name end) -- prints the monitor name for each monitor

-- Results from functions are stored in tables
local sizes = group.getSize()
local size = sizes.monitor_0
print(size[1]..'x'..size[2]) --> (the size of monitor_0)

Screenshots
Spoiler
Spoiler
(there's a connection error in this image that I fixed prior to testing the script, just ignore it :P/>/> )
Spoiler
Spoiler
Spoiler
Spoiler
Spoiler

Code for "peripheral-abuse" program:
Spoiler

os.loadAPI('netgroup')

local group = netgroup.wrap('back','monitor')

group.setBackgroundColor(colors.black)
group.setTextColor(function() return 2^math.random(14) end)
group.setCursorPos(1,1)
group.setTextScale(2)
group.clear()
group.write(function(mon, name) local w,h = mon.getSize() return w..'x'..h end)

group.filter('printer')

group.newPage()
group.setPageTitle('It works!')
group.write('Like a boss.')
group.endPage()

group.filter('computer')

group.turnOn()

Download: pastebin get rfMuKz2t netgroup
Nathan1852 #2
Posted 17 March 2013 - 08:33 AM
-Edited because of Derp-
Yopu #3
Posted 17 March 2013 - 10:48 AM
Really interesting code. I'll have to play around with it. Nice work!
Kingdaro #4
Posted 17 March 2013 - 04:55 PM
Really interesting code. I'll have to play around with it. Nice work!
Thanks!
remiX #5
Posted 18 March 2013 - 10:12 AM
This will come in real handy when handling multiple monitors for just about everything :P/>
Nuclear reactor, turtle information… Everything !

Good job
elexx #6
Posted 18 March 2013 - 10:18 PM
Wow man. I really love the way you coded the thing. Have to test this and play around a bit!
KleptoKat #7
Posted 31 March 2013 - 06:00 PM
Really neat code, reads fantastic.
superaxander #8
Posted 09 April 2013 - 02:36 AM
Awesome!!
ElvishJerricco #9
Posted 18 April 2013 - 03:54 PM
This is actually really cool. Useful for a few things. Well done.