Jump to content




how do I autowrap peripherals on wired network?


2 replies to this topic

#1 qwerty

  • Members
  • 72 posts
  • LocationThe Sand Dunes

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

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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().

#3 qwerty

  • Members
  • 72 posts
  • LocationThe Sand Dunes

Posted 25 February 2020 - 02:06 AM

View PostLyqyd, on 25 February 2020 - 01:18 AM, said:

... 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?

View PostLyqyd, on 25 February 2020 - 01:18 AM, said:

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

View PostLyqyd, on 25 February 2020 - 01:18 AM, said:

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 by qwerty, 25 February 2020 - 02:41 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users