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

[Question]Redpower2 bundled cable checking

Started by TheOnlyAnti, 14 March 2012 - 06:01 AM
TheOnlyAnti #1
Posted 14 March 2012 - 07:01 AM
First time here, Hi.

Anyway, i just started working with computer craft and as a basic program to start off i am attempting to control my town lights with a simple menu.
However, the problem i am having is that when i display my menu. i show "Lights are On" or "Lights are Off" and first used just redstone wire to
the back of the computer and as i adapted more possibilities to turn on other things through out my town i upgraded the restone wire to
bundled cable. But now the menu of saying something is on or off isnt working. I am having trouble checking my bundled cables.

Here is my code i am currently using with just Lights functions
I know there are probably minor ways to fix certain things, but im mainly looking for checking the cables.
Also, is there a way to turn no cables on? Like once ive set white, to turn just it off or none on?

local exit = "0"
while exit == "0" do
shell.run("clear")
print(" ")
print("		  **Control Panel Status**")
write("    1. Lights - ")
if rs.testBundledInput("back", colors.white) == true then
print("On")
else
print("Off")
end
print(" ")
print(" ")
print(" ")
write("    Hit enter to continue... ")
input = read()
shell.run("clear")
print(" ")
print("	    **Control Panel Operations**")
write("    1. Turn Lights ")
if rs.testBundledIntput("back", colors.white) == true then
print("Off")
else
print("On")
end
print("    2. Exit")
print(" ")
print(" ")
write("    Choice: ")
input = read()
if input == "1" then
if rs.testBundledInput("back", colors.white) == true then
rs.setBundledOutput("back", colors.white)
print("Lights are now off")
else
rs.setBundledOutput("back", colors.black)
print("Lights are now on")
end
if input == "2" then
exit = "1"
end
end
end

Thanks in advance,
The One and Only Anti
Casper7526 #2
Posted 14 March 2012 - 07:40 AM
When you set a bundle cable it takes that new setting regardless of the old setting.

For example

rs.setBundledOutput(side, colors.white)
rs.setBundledOutput(side, colors.black)

The bundle output is now black and black only.

If you want to remove all output you can do

rs.setBundledOutput(side, 0)
TheOnlyAnti #3
Posted 14 March 2012 - 07:45 AM
Alright thank you for answering that, Any idea on the Getting wether a cable is on or not? Perhaps i should store a variable?

Edit:
Fixed with using a variable.

With some more thought, i am attempting now to create an array of wires that are on. So say i turn lights on, white is on. But i want to turn on my factory as well, but both be on. I need to add them to an array of some sort i would assume instead of a mass check of variables which would just be a stupid amount of code. How could i do this simply? I know to make a array is just Powered = {}, but adding the colors of cables has me confused now.
Any help?

Thanks,
The One and Only Anti
Casper7526 #4
Posted 14 March 2012 - 08:32 AM
Just use a variable

output = 0

output = colors.combine(output, colors.white)
rs.setBundledOutput(side, output)
-- white is now on
output = colors.combine(output, colors.blue + colors.yellow)
rs.setBundledOutput(side, output)
-- white blue and yellow are now on
output = colors.subtract(output, colors.yellow)
rs.setBundledOutput(side, output)
-- white and blue are now on
TheOnlyAnti #5
Posted 14 March 2012 - 08:35 AM
O wow, much simpler than i thought. Thank you very much and thanks for the quick response.
Thank you for all your help,
The One and Only Anti
TheOnlyAnti #6
Posted 14 March 2012 - 09:21 AM
While not on the same, topic persay. Is there a way to jump up to a section of code that ran prior?
Im looking to have a lock function for the computer that would require a password to be entered again.
I read that the you can set the program to run on start up, so if you set the program as start up then exit the program it would re-run it?

The best would be, when i close the terminal it re-locks and requires a password to be entered.
Any ideas?

Thanks in advance,
The One and Only Anti