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

Toggle Bundled Cable outputs?

Started by ledz99, 25 December 2016 - 02:34 PM
ledz99 #1
Posted 25 December 2016 - 03:34 PM
Hi, new here and still learning. Have another question, a problem I ran into.

I'm creating a program with craftOS 1.3. The program is meant to have bundled cable outputs assigned to different colors of wire. I found that I cannot toggle the outputs. I can turn on say blue1, to turn it off I either have to turn all off with 0 or turn on another say white2. Is there a way to toggle the outputs individually without affecting the others? I read that this couldn't be done, but I'm not sure. If this isn't possible, is there a way to have my os.pullEvent allow for a word/number i.e. more than 1 character or something…

If I run say 10 outputs and have them all indivually coded aswell as different configurations say blue+white+gray or red+gray+blue+white… thats what… the powerset of 10?… thats not even possible to code… (for me anyways, lol). And for all 16 colors… 65,536 configurations… is there any way around this or would I literally just have to code all that? Not to mention that pretty quickly all of your keys on the keyboard are used..

Could someone help me or give me a quick reference to information about this? Thanks again!
Edited on 25 December 2016 - 03:30 PM
Lupus590 #2
Posted 25 December 2016 - 07:09 PM
Have you looked at the functions of the colours API? http://www.computerc...iki/Colors_(API)

Edit: Fix link
Edited on 26 December 2016 - 01:06 PM
ledz99 #3
Posted 26 December 2016 - 01:07 PM
Have you looked at the functions of the colours API? http://www.computerc...iki/Colors_(API)

Yeah but in order to make them seem like they are 'toggleable' i'd still have to code a multitude of configurations right?

For only 3 colors like red green and blue I'd have to have

1. Red
2. Blue
3. Green
4. Red+Blue
5. Red+Green
6. Blue+Green
7. Red+Blue+Green
8. 0

that's not bad but for all 16 colors its insane
Edited on 26 December 2016 - 12:09 PM
KingofGamesYami #4
Posted 26 December 2016 - 01:25 PM
You can generate that number "on the fly" using colors.combine and colors.subtract to modify the color you last set it to.
Edited on 26 December 2016 - 01:30 PM
Lupus590 #5
Posted 26 December 2016 - 02:05 PM
You can generate that number "on the fly" using colors.combine and colors.subtract to modify the color you last set it to.
fixed it for you
ledz99 #6
Posted 26 December 2016 - 03:19 PM
Ok thanks guys! I started to figure as much, didn't wanna have to do that for each time but I guess that's the only plausible way unless someone has wrote an API or if I could figure out how to write one that toggled bundled cable, thanks again!
Edited on 26 December 2016 - 02:19 PM
Lyqyd #7
Posted 26 December 2016 - 11:21 PM
This function sets a bundled color output to a given state without affecting any of the other color output on that side.

function setBundledColor(side, color, state)
	if state then
		if not colors.test(rs.getBundledOutput(side), color) then
			rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
		end
	else
		if colors.test(rs.getBundledOutput(side), color) then
			rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
		end
	end
end

This function toggles a bundled output color on a side without affecting any other bundled outputs on that side.

function toggleBundledColor(side, color)
	rs.setBundledOutput(side, (colors.test(rs.getBundledOutput(side), color) and colors.subtract(rs.getBundledOutput(side), color) or colors.combine(rs.getBundledOutput(side), color)))
end
ledz99 #8
Posted 27 December 2016 - 02:16 AM
This function sets a bundled color output to a given state without affecting any of the other color output on that side.

function setBundledColor(side, color, state)
	if state then
		if not colors.test(rs.getBundledOutput(side), color) then
			rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
		end
	else
		if colors.test(rs.getBundledOutput(side), color) then
			rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
		end
	end
end

This function toggles a bundled output color on a side without affecting any other bundled outputs on that side.

function toggleBundledColor(side, color)
	rs.setBundledOutput(side, (colors.test(rs.getBundledOutput(side), color) and colors.subtract(rs.getBundledOutput(side), color) or colors.combine(rs.getBundledOutput(side), color)))
end

AHH! Thank you so much!! I got it working just how I wanted it to, as I'm really really new to all this I was overthinking it… all it needed was a function!