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

[Question]How can I output multiple colored bundled cable signals from one computer?

Started by Joe12o, 30 April 2012 - 08:52 PM
Joe12o #1
Posted 30 April 2012 - 10:52 PM
I have a script that toggles all of my machines on and off, but I need the computer to output multiple colored signals from the same side, but I can't seem to figure it out. If I have one color on and I try to toggle another on at the same time the new color turns on, but the color that was on previously turns off. If I toggle any of them off they all turn off.

To toggle on I use:

tree = colors.combine(tree,colors.red)
rs.setBundledOutput("back",tree)

To toggle off I use:

tree = colors.subtract(tree,colors.red)
rs.setBundledOutput("back",tree)

I do, of course, use a different color and variable on each machine so they don't seem to be conflicting. Is this possible to do from one side of a computer?
Zalerinian #2
Posted 01 May 2012 - 02:03 AM
well now according to http://computercraft.info/wiki/index.php?title=Redstone.setBundledOutput You are triyng to combine an invalid color.


print(colors.combine(colors.white, colors.magenta, colours.lightBlue)) (from http://computercraft.info/wiki/index.php?title=Colors.combine])

As far as i'm aware, tree is not valid color. Try fixing it to use valid colors. If i am, however completely wrong, do let me know.
MysticT #3
Posted 01 May 2012 - 03:16 AM
well now according to http://computercraft...etBundledOutput You are triyng to combine an invalid color.


print(colors.combine(colors.white, colors.magenta, colours.lightBlue)) (from http://computercraft...=Colors.combine])

As far as i'm aware, tree is not valid color. Try fixing it to use valid colors. If i am, however completely wrong, do let me know.
"tree" is a variable used to contain the colors. It's perfectly valid to do that.

There's an example of how to do it:

local tree = colors.red -- set the initial value of the variable
rs.setBundledOutput("back", tree) -- output now is red
tree = colors.combine(tree, colors.white, colors.blue) -- add some colors
rs.setBundledOutput("back", tree) -- output now is red, white and blue
tree = colors.subtract(tree, colors.white) -- remove the white
rs.setBundledOutput("back", tree) -- output now is red and blue

These are two functions I use to add and remove output easier:

local function AddOutput(sSide, ...)
  local c = colors.combine(rs.getBundledOutput(sSide), ...)
  rs.setBundledOutput(sSide, c)
end

local function RemoveOutput(sSide, ...)
  local c = colors.subtract(rs.getBundledOutput(sSide), ...)
  rs.setBundledOutput(sSide, c)
end
You use them like this:

AddOutput("back", colors.white, colors.brown, colors.black)
RemoveOutput("back", colors.black)

Come back with any questions you have and we'll try to help :)/>/>
Joe12o #4
Posted 01 May 2012 - 04:44 AM
well now according to http://computercraft...etBundledOutput You are triyng to combine an invalid color.


print(colors.combine(colors.white, colors.magenta, colours.lightBlue)) (from http://computercraft...=Colors.combine])

As far as i'm aware, tree is not valid color. Try fixing it to use valid colors. If i am, however completely wrong, do let me know.
"tree" is a variable used to contain the colors. It's perfectly valid to do that.

There's an example of how to do it:

local tree = colors.red -- set the initial value of the variable
rs.setBundledOutput("back", tree) -- output now is red
tree = colors.combine(tree, colors.white, colors.blue) -- add some colors
rs.setBundledOutput("back", tree) -- output now is red, white and blue
tree = colors.subtract(tree, colors.white) -- remove the white
rs.setBundledOutput("back", tree) -- output now is red and blue

These are two functions I use to add and remove output easier:

local function AddOutput(sSide, ...)
  local c = colors.combine(rs.getBundledOutput(sSide), ...)
  rs.setBundledOutput(sSide, c)
end

local function RemoveOutput(sSide, ...)
  local c = colors.subtract(rs.getBundledOutput(sSide), ...)
  rs.setBundledOutput(sSide, c)
end
You use them like this:

AddOutput("back", colors.white, colors.brown, colors.black)
RemoveOutput("back", colors.black)

Come back with any questions you have and we'll try to help :)/>/>
So I would need a single variable to contain all of the colors I want to have receiving a signal at the same time? I was using multiple variables just in case because I just started learning lua, although it isn't very different from other programming languages I know.

So, for example, I could do this?:

local tree = colors.blue
if(blah == true) then
	tree = colors.combine(tree, colors.green, colors.red)
    rs.setBundledOutput("back", tree)
end
if(otherBlah == true) then
	tree = colors.combine(tree, colors.white)
    rs.setBundledOutput("back", tree)
end
This would maintain the original color, blue, and the other colors would be added afterwards, correct?(This code might have errors, it's just an example I thought of while typing this) The code I have right now is similar to the one above, but I have a different variable for each new color I want to add, like this:

if(blah == true) then
	tree = colors.combine(tree, colors.white)
    rs.setBundledOutput("back", tree)
end
if(otherBlah == true) then
	reactor = colors.combine(reactor, colors.blue)
    rs.setBundledOutput("back", reactor)
end
This would cause the problems I had described above correct?

Well, after reading this post through I realized I am just being dumb and failed to notice the colors.COMBINE, but some of the questions asked have a point and if you could correct me if I was wrong in anything I said that would be nice. Thanks for the help!
Luanub #5
Posted 01 May 2012 - 05:02 AM
You are correct you want to use 1 var for the colors. function and in the redstone. functions. So you will want to use something similar to the first example


local tree = colors.blue
if(blah == true) then
        tree = colors.combine(tree, colors.green, colors.red)
end
if(otherBlah == true) then
        tree = colors.combine(tree, colors.white)
end
cyon #6
Posted 26 January 2013 - 06:11 PM
Hi, I realize this is long after this thread was last posted on, but I've followed some of the above advice and find that it's only working slightly for me. Keep in mind, I'm very new to this and I don't know coding very well.

Now, after I set up some of the coding from the last two posts, I can get the output to power a red wire, a yellow wire, or both (Which is good!). However, that said, it doesn't work the way I want it to. I have the variables set up so that when one is true the red wire's powered, and a different one for the yellow wire. Then another for them both at the same time, which powers both. The issue I'm getting is this:

In the first program, if I enter "mass" it'll send me to a new program called "mass." In "mass" I have it set up so when I press "on" the first variable will be set to "true," which SHOULD (In my mind) turn the red wire on. This, however, doesn't happen, and to get it to work I must return to the original program and then type something random so the default directory thing comes back up. Then all of a sudden it's turned on! Not sure how to get around this…

By the way, I used "tree" just as Joe12o did to make it less confusing for myself… Please keep in mind again that I'm not very good at this… So if something's horrible wrong I apologize!


os.pullEvent = os.pullEventRaw
shell.run "clear"
print("This is a test")
x = io.read()
write("")
local tree = colors.red
if x == "mass" then
shell.run "mass"
elseif x == "nuke" then
shell.run "nuke"
end
if (blah == true) then
tree = colors.combine(tree)
rs.setBundledOutput("back", tree)
end
if (otherblah == true) then
tree = colors.combine(colors.yellow)
rs.setBundledOutput("back", tree)
end
if (blah == true) and (otherblah == true) then
tree = colors.combine(colors.red, colors.yellow)
rs.setBundledOutput("back", tree)
end

Any help is appreciated!
Dlcruz129 #7
Posted 26 January 2013 - 06:16 PM
Where are "blah" and "otherblah" defined? May we see your mass and nuke programs?
cyon #8
Posted 26 January 2013 - 06:19 PM
Where are "blah" and "otherblah" defined? May we see your mass and nuke programs?

Ah, yes, and "mass" and "nuke" are the same other than "blah" being "otherblah" and vice versa.


os.pullEvent = os.pullEventRaw
print("This is MASS.")
x = io.read()
write("")
if x == "on" then
blah = true
shell.run "door"
elseif x == "off" then
blah = false
shell.run "door"
end

EDIT: The original program is called "door"..it's a habit of mine.
Luanub #9
Posted 26 January 2013 - 07:04 PM
Its not working properly because blah and otherblah are not defined in the original program "door".

What I would recommend doing is rather then using three separate programs to put them all into 1 program. There's no real reason why they need to be separated. Just make the two other programs "mass" and "nuke" functions within the door program then change the following in the door programs original code.

if x == "mass" then
shell.run "mass"
elseif x == "nuke" then
shell.run "nuke"
end

--to
if x == "mass" then
mass()
elseif x == "nuke" then
nuke()
end

cyon #10
Posted 27 January 2013 - 10:04 AM
Alright, so I didn't work, then I moved some things around and now it does!…sort of. If I say 'mass' then 'on' then red wire turns on. Then 'nuke' then 'on' and they both are on (perfect!) but then there's the problem. If I say 'nuke' 'off' OR 'mass' 'off' either of them will turn off the red wire off at this point. Also, if I turn mass on or nuke on by itself, I can't turn them off. The only way to unpower either of them is to have them both on, and at that point I can only turn the red off. It's interesting…not sure why this happens. Thanks for the help so far! Code:


function mass()
   x = io.read()
   write("")
   if x == "on" then
   blah = true
   shell.run "test"
   elseif x == "off" then
   blah = false
   shell.run "test"
   end
end
function nuke()
   x = io.read()
   write("")
   if x == "on" then
   otherblah = true
   shell.run "test"
   elseif x == "off" then
   otherblah = false
   shell.run "test"
   end
end
local tree = colors.red
if (blah == true) then
tree = colors.combine(tree)
rs.setBundledOutput("back", tree)
end
if (otherblah == true) then
tree = colors.combine(colors.yellow)
rs.setBundledOutput("back", tree)
end
if (blah == true) and (otherblah == true) then
tree = colors.combine(colors.red, colors.yellow)
rs.setBundledOutput("back", tree)
end
os.pullEvent = os.pullEventRaw
shell.run "clear"
print("This is a test")
x = io.read()
write("")
if x == "mass" then
mass()
elseif x == "nuke" then
nuke()
end
Luanub #11
Posted 27 January 2013 - 10:53 AM
To turn them off just subtract the colors you want to turn off.

tree = colors.subtract(colors.red)
rs.setBundledOutput("back", tree) -- would turn off red and leave the rest on
cyon #12
Posted 27 January 2013 - 11:02 AM
I tried this once…
Would my code look like this?…


if (blah == true) then
tree = colors.combine(tree)
rs.setBundledOutput("back", tree)
end
if (blah == false) then
tree = colors.subtract(colors.red)
rs.setBundledOutput("back", tree)
end
I tried this and for whatever reason it doesn't turn off once it's turned on. It stays on no matter what.
Also, if I add:

if not (blah == true) then
tree = colors.subtract(colors.red)
rs.setBundledOutput("back", tree)
end
It will turn the red wire on the second the computer's booted.