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

Arrays

Started by dorky106, 25 July 2013 - 09:38 AM
dorky106 #1
Posted 25 July 2013 - 11:38 AM
is there any faster way I can wrap peripherals to a array or is typing them out the fastest way I can do it?
I'm trying to get the power in all my redstone energy cells as one value to keep a eye on how much power I have. I have 30 cells to check is the reason I'm asking.
Kingdaro #2
Posted 25 July 2013 - 11:47 AM
I assume your 30 cells are all connected via wired peripheral cables, and if so, you can use a loop with modem.getNames().


 --# replace "back" with the side of your modem
local names = peripheral.call('back', 'getNames')
local cells = {}

for i=1, #names do
  table.insert(cells, peripheral.wrap(names[i]))
end
dorky106 #3
Posted 31 July 2013 - 11:19 AM
its saying getNames doesnt exist
(sorry been sorry so havent been able to get back)
Lyqyd #4
Posted 31 July 2013 - 12:34 PM
It's getNamesRemote. I'm fairly certain you could replace the whole peripheral.call with a peripheral.getNames() (though that would also give you the modem, not just the remote peripherals).