Jump to content




Open multiple modems + assign variable


  • You cannot reply to this topic
3 replies to this topic

#1 lifewcody

  • Members
  • 143 posts
  • Locationstill looking....

Posted 15 February 2015 - 12:35 AM

This is sort of hard to clarify, so bear with me.

I have a random amount of modems on a computer, I get them using this:
local lSides = redstone.getSides()
local lCSides = {}
for i=1, #lSides do
  if peripheral.isPresent(lSides[i]) and peripheral.getType(lSides[i]) == "modem" then
	table.insert(lCSides, lSides[i])
  end
end

This puts all of the sides modems are connected to in lCSides (ListConnectedSides)

I then try to open 1 - 128 channels on each modem. Problem I have is, I need to assign variables to the modems to transmit.

So if lCSides[1] == "left" then I need to be able to do table[2].transmit(1, 2, "Test)

This is the code I am having difficulty on:

for s=1, #lCSides do
  for c=1, 128 do
	lCSides[s].peripheral.wrap(lCSides[s])
	lCSides[s].open(c)
  end
end


#2 Lignum

  • Members
  • 558 posts

Posted 15 February 2015 - 12:41 AM

You can use peripheral.find for this:
local modems = { peripheral.find("modem") }
for _,v in pairs(modems) do
   for i=1,128 do
      v.open(i)
   end
end


#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 15 February 2015 - 12:42 AM

Looks like you meant to do:

for s=1, #lCSides do
  lCSides[s] = peripheral.wrap(lCSides[s])

  for c=1, 128 do
        lCSides[s].open(c)
  end
end

peripheral.find() is indeed easier, if you're on CC 1.6 or later.

I do find myself thinking that whatever you're trying to achieve by opening that many channels, there's a way to do it with just one or two.

Edited by Bomb Bloke, 15 February 2015 - 12:43 AM.


#4 lifewcody

  • Members
  • 143 posts
  • Locationstill looking....

Posted 15 February 2015 - 12:44 AM

View PostBomb Bloke, on 15 February 2015 - 12:42 AM, said:

Looks like you meant to do:

for s=1, #lCSides do
  lCSides[s] = peripheral.wrap(lCSides[s])

  for c=1, 128 do
		lCSides[s].open(c)
  end
end

peripheral.find() is indeed easier, if you're on CC 1.6 or later.

I do find myself thinking that whatever you're trying to achieve by opening that many channels, there's a way to do it with just one or two.

I'm redesigning my InZernet protocol and it will work with sending / receiving channels

Edit: Your reply worked! Thank you

Edited by jubba890, 15 February 2015 - 12:46 AM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users