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

red power bundled cables input

Started by Lasere123456, 26 July 2012 - 02:17 PM
Lasere123456 #1
Posted 26 July 2012 - 04:17 PM
Hello people:D
i just found this mod 5 days ago and have been studying programming ever since!

At the moment i am working on a control panel controlling 5 different systems.
it is in working condition (it can toggle stuff on or off atm), but i want to add a indicator for each system.
so since i knew bundled cables are a pain to work whit i did a experiment.


if rs.getBundledInput("back", colors.white ) then
print("white wire is on")
elseif rs.getBundledInput("back", colors.orange ) then
print("orange wire is on")
else
print("No wire is on")
end

but i always outputs:
White wire is on

always!!
OmegaVest #2
Posted 26 July 2012 - 04:25 PM
Okay, so getBundledInput just outputs a number. If White is on, then it will be 1, while if orange is on it's 2. Both being on makes it 3. Binary counting.

So, to get what you are looking for, you can either capture the number to a variable and check for the number to match what you are looking for. Or you can use testBundledInput, which is probably what you wanted in the beginning, as it uses those parameters.
Lasere123456 #3
Posted 26 July 2012 - 04:37 PM
Thx, mate after some searching after the test bundle ting i found the code i needed:

print(redstone.testBundledInput("back", colors.white))
Cranium #4
Posted 26 July 2012 - 09:16 PM
Furthermor, wou can make that code a little "shinier" by setting it up this way:

function colorTest(side, color)
  if (redstone.testBundledInput("side", colors.color)) = true then
  print(color, " wire is on.")
  elseif (redstone.testBundledInput("side", colors.color)) = false then
  print(color, " wire is off.")
  end
end
you should be able to call back to that function several times with any color/side you want by inputting colorTest(side, color) wherever you want, and replacing the side and color appropriately.
Noodle #5
Posted 26 July 2012 - 10:12 PM
Just fixing your code a bit..
function colorTest(side, color)
  if rs.testBundledInput(side, colors.color) then
    print(color .." wire is on.")
  elseif rs.testBundledInput(side, colors.color) then
    print(color .." wire is on.")
  end
end
OmegaVest #6
Posted 26 July 2012 - 10:20 PM
Actually, the commas would have worked as well. And, in cases where you are trying to concatenate numbers and strings, they are the only way to go (with print, that is).
Noodle #7
Posted 26 July 2012 - 10:22 PM
Yes but his code wouldn't of worked because of the "= true" not "== true" or just nothing. More efficient: rs.* and no = true.
OmegaVest #8
Posted 26 July 2012 - 10:30 PM
I wasn't disputing that. Just, a quirk of mine: I make code work for everything, even if I'm only using it in a very specific way, and only on SSP. So, I commented about commas versus concatenation.


EDIT: Which, by the way, sounds awesome if you say it out loud. Like a cheesy coder debate topic.
Cranium #9
Posted 27 July 2012 - 12:58 AM
thanks for the fix….i guess??? was it wrong or not, i'm confused…
Lyqyd #10
Posted 27 July 2012 - 01:20 AM
Here's a version that would actually work:


function colorTest(side, color)
  if redstone.testBundledInput(side, colors[color]) then
	print(color.." wire is on.")
  else
	print(color.." wire is off.")
  end
end