33 posts
Posted 25 December 2013 - 11:27 AM
I'm trying to work out how to detect all the batboxes, MFSU's, CESU's etc… on a network ?
Just I'm sure someone has done it before… if anyone can point me at where, I'd be obliged.
Thanks for any help.
758 posts
Location
Budapest, Hungary
Posted 25 December 2013 - 12:04 PM
I assume you're talking about peripheral networks. If that's the case, all the batboxes, MFSU's and things like that are peripherals. Suppose you have them connected to a computer. You can go and call
peripheral.getNames() to get a list of all connected peripherals on that network (and the peripherals which connect to the computer directly).
local connectedPeripherals = peripheral.getNames()
for ix = 1, #connectedPeripherals do
print(connectedPeripherals[ix] .. ": " .. peripheral.getType(connectedPeripherals[ix]))
end
Edited on 25 December 2013 - 11:04 AM
33 posts
Posted 25 December 2013 - 12:34 PM
Ah yeah sorry, I probably wasn't clear enough - I'm really after the function that handles the array with all the names in it and "does something with that" :)/>
I just want to add up the power for particular parts of the network and send it to screen.
I will handle the screen handling just not too sure about the array itself. That's why I'm after example code, it will have everything in it.
Edited on 25 December 2013 - 11:36 AM
1852 posts
Location
Sweden
Posted 25 December 2013 - 01:32 PM
To simplify LBPHacker's code
for _, name in ipairs( peripheral.getNames() ) do
print( name .. ":" .. peripheral.getType( name ) )
end
So you know, peripheral.getNames() returns a table.
EDIT: So you want to use the batboxes etc? Well then you should wrap them
local batboxes = {}
--# Get all batboxes attached
for _, name in ipairs( peripheral.getNames() ) do
if peripheral.getType( name ) == "batbox" then
nBox = {}
nBox.name = name
table.insert( batboxes, batbox )
end
end
--# Wrap them
for i = 1, #batboxes do
batboxes[i].name = peripheral.wrap( batboxes[i].name )
end
But I'm not sure what the type for batbox is so I just put batbox, Run the first code to check and then change batbox in this part if it is something else than that.
if peripheral.getType( name ) == "batbox" then
Edited on 27 December 2013 - 09:01 AM
758 posts
Location
Budapest, Hungary
Posted 25 December 2013 - 06:48 PM
if type( name ) == "batbox" then
string…
1852 posts
Location
Sweden
Posted 26 December 2013 - 11:41 AM
if type( name ) == "batbox" then
string…
What? You check with strings when you check peripherals
for _, name in ipairs( peripheral.getNames() ) do
if peripheral.getType( name ) == "monitor" then
print("This was a monitor!")
break
end
end
Edited on 27 December 2013 - 09:02 AM
758 posts
Location
Budapest, Hungary
Posted 26 December 2013 - 12:24 PM
-snip-
But checking the
type of a
string returns "string". Did you mean
peripheral.getType?
1852 posts
Location
Sweden
Posted 27 December 2013 - 10:00 AM
-snip-
But checking the
type of a
string returns "string". Did you mean
peripheral.getType?
Oh.. Derp xD
Yeah, I'll edit the post above, Thanks! :)/>
33 posts
Posted 28 December 2013 - 02:37 AM
I should be able to replace a modem/cable with a wireless modem on the batbox ?
Also, I notice nothing happens when I right-click the wireless modems, unlike the wired ones.
table.insert( batboxes, batbox )
Did you mean nBox here? I don't see a reference to batbox anywhere ?
This is what I have so far -
http://pastebin.com/ZScuw3fYHowever, it outputs nothing to screen (perhaps I handled that wrong?)
There's a wireless modem both on a batbox and a CESU just for testing.
Thanks.
Edited on 28 December 2013 - 01:48 AM
7508 posts
Location
Australia
Posted 28 December 2013 - 03:26 AM
I should be able to replace a modem/cable with a wireless modem on the batbox ?
No, only wired modems can act as peripheral handlers, wireless modems are only for wireless communications.
33 posts
Posted 28 December 2013 - 05:02 AM
argh, no wonder. Thanks for that bit of info.