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

clearing peripheral index

Started by TwitchBlade, 12 August 2014 - 11:48 AM
TwitchBlade #1
Posted 12 August 2014 - 01:48 PM
i want to know if there is anyway to reset the peripheral index e.g.

i connect monitor 1 and it connects as monitor_0
then i connect monitor two as monitor_1
but if i disconect one and reconnect it becomes monitor_3 can i reset that?
theoriginalbit #2
Posted 12 August 2014 - 03:13 PM
You can, but it is not recommended, especially in a server situation.

In your Minecraft save folder there is a folder called computer, in that folder there will be a series of text files that are the last id for the peripherals, delete the appropriate files and reconnect all your peripherals in-game.
TwitchBlade #3
Posted 12 August 2014 - 03:24 PM
then is there a more proper way inside of a program then to hard code them and there number in?
KingofGamesYami #4
Posted 12 August 2014 - 03:51 PM
then is there a more proper way inside of a program then to hard code them and there number in?
The best way to connect peripherals inside a program is by iterating through the names.

local mon
for _, v in ipairs( peripheral.getNames() ) do
 if v:sub( 1, 7 ) == "monitor" then
  mon = peripheral.wrap( v )
 end
end
theoriginalbit #5
Posted 12 August 2014 - 04:15 PM
alternatively, if you're using ComputerCraft 1.6 and above you can use the peripheral.find function. Both examples on the wiki are good to show usage, the one that isn't shown is the fact that you can get multiple peripherals back from it as well

local allMonitors = { peripheral.find("monitor") }