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

how do I autowrap peripherals on wired network?

Started by qwerty, 24 February 2020 - 10:53 PM
qwerty #1
Posted 24 February 2020 - 11:53 PM
Once more I am asking for your divine guidance with a problem of peripherals.
namely: how do I automatically wrap them when -the computer turns on or when a new peripheral is attached via wired modem.

so far I've come up with using string.find() to compare things, but peripheral.getNames() gives a table so that's more manipulation than I know. besides, trying to detect witch reference instance was found is rather difficult for me.

case and point: this is what I'm trying to accomplish.

reference = {chest, crate, cache}
List =  peripheral.getNames()

--code I have no idea on how to construct--

pointer = peripheral.wrap(*inventory from list*)
reference_id** = pointer

-- ** > the reference and id are to be used as pointers to selected inventory --

P.S. I'm using cc:tweaked if it wasn't allready obvious

with regards
-qwerty
Lyqyd #2
Posted 25 February 2020 - 01:18 AM
Maybe I'm not quite reading the question right, but it seems like the easiest method would be to maintain a table keyed by the peripheral names, with the value being the "wrapped" peripheral. Then you can iterate over the table for access, and use the peripheral connection event to update the contents of the table.

In fact, I think you can skip the table of wrapped peripherals entirely and simply iterate over the connected peripherals table returned by getNames().
qwerty #3
Posted 25 February 2020 - 02:06 AM
… it seems like the easiest method would be to maintain a table keyed by the peripheral names, with the value being the "wrapped" peripheral. you can iterate over the table for access…
sounds good, and I'll try it, but would you be so kind as to provide a snippet of code I could use?

…and use the peripheral connection event to update the contents of the table.
literally what I was gonna do.

In fact, I think you can skip the table of wrapped peripherals entirely and simply iterate over the connected peripherals table returned by getNames().
so just use peripheral.call() insead of .wrap()? and parse the table entry to work in a peripheral call, I assume.

P.S. how do I compare two table contents? i.e. table_0 has [boolean] and I'm comparing to table_1's [47] to determine stuff


with regards
-qwerty
Edited on 25 February 2020 - 01:41 AM