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

Question: How do I check bundled cable output?

Started by Cheska, 11 March 2012 - 08:53 PM
Cheska #1
Posted 11 March 2012 - 09:53 PM
Hey you guys!

I'm pretty new to Computercraft and coding and general and trying to write a program to run my refinery. I'm trying to read if the computer set an output for a specific cable to tell me in the control screen if the regarding machine is turned on (gets a signal from the computer) or not.

First I'll post the code I had till now.

shell.run("clear")
print("----------------------------------")
sleep(0.1)
print("|		 Controls			   |")
sleep(0.1)
print("| 1. Oilpumps and refinery - OFF |")
sleep(0.1)
print("| 2. Engines - fuel - OFF		|")
sleep(0.1)
print("| 3. Engines - water - OFF	   |")
sleep(0.1)
print("| 4. Engines start - OFF		 |")
sleep(0.1)
print("| 5. Waterpumps - OFF			|")
sleep(0.1)
print("| 6. Exit						|")
sleep(0.1)
print("----------------------------------")

input = read()

if input == "1" then
print("Engaging")
sleep(1.0)
rs.setBundledOutput("bottom", colors.white)
print("Oil pumps and refinery engaged")
sleep(2.0)
shell.run("rom/programs/custom/refinerycontrol.txt")
elseif input == "2" then
print("Engaging")
sleep(1.0)
rs.setBundledOutput("bottom", colors.black)
print("Engine fuel engaged")
sleep(2.0)
shell.run("rom/programs/custom/refinerycontrol.txt")
elseif input == "3" then
print("Engaging")
sleep(1.0)
rs.setBundledOutput("bottom", colors.yellow)
rs.setBundledOutput("back", colors.yellow)
print("Engine water engaged")
sleep(2.0)
shell.run("rom/programs/custom/refinerycontrol.txt")
elseif input == "4" then
print("Engaging")
sleep(1.0)
rs.setBundledOutput("bottom", colors.red)
print("Engines engaged")
sleep(2.0)
shell.run("rom/programs/custom/refinerycontrol.txt")
elseif input == "5" then
print("Engaging")
sleep(1.0)
rs.setBundledOutput("bottom", colors.orange)
rs.setBundledOutput("back", colors.orange)
print("Waterpumps engaged")
sleep(2.0)
shell.run("rom/programs/custom/refinerycontrol.txt")
elseif input == "6" then
shell.run("exit")
elseif input == other then
print("Please type the number")
sleep(2.0)
shell.run("refinerycontrol.txt")
else print("not available")
shell.run("rom/programs/custom/refinerycontrol.txt")
end

Now I'm trying to toggle this label "OFF". Instead of reading the Output and printing the regarding message it just sets the output..


shell.run("clear")
  print("----------------------------------")
   sleep(0.1)
  print("|		 Controls			   |")
   sleep(0.1)
  
if rs.setBundledOutput("bottom", colors.white) == TRUE then
  print("| 1. Oilpumps and refinery - ON  |")
else
  print("| 1. Oilpumps and refinery - OFF |")
end
   sleep(0.1)
print("| 2. Engines - fuel - OFF		|")
sleep(0.1)
print("| 3. Engines - water - OFF	   |")
sleep(0.1)
print("| 4. Engines start - OFF		 |")
sleep(0.1)
print("| 5. Waterpumps - OFF			|")
sleep(0.1)
print("| 6. Exit						|")
sleep(0.1)
print("----------------------------------")

input = read()

if input == "1" then
print("Engaging")
sleep(1.0)
rs.setBundledOutput("bottom", colors.white)
print("Oil pumps and refinery engaged")
sleep(2.0)
shell.run("rom/programs/custom/refinerycontrol.txt")
elseif input == "2" then
print("Engaging")
sleep(1.0)
rs.setBundledOutput("bottom", colors.black)
print("Engine fuel engaged")
sleep(2.0)
shell.run("rom/programs/custom/refinerycontrol.txt")
elseif input == "3" then
print("Engaging")
sleep(1.0)
rs.setBundledOutput("bottom", colors.yellow)
rs.setBundledOutput("back", colors.yellow)
print("Engine water engaged")
sleep(2.0)
shell.run("rom/programs/custom/refinerycontrol.txt")
elseif input == "4" then
print("Engaging")
sleep(1.0)
rs.setBundledOutput("bottom", colors.red)
print("Engines engaged")
sleep(2.0)
shell.run("rom/programs/custom/refinerycontrol.txt")
elseif input == "5" then
print("Engaging")
sleep(1.0)
rs.setBundledOutput("bottom", colors.orange)
rs.setBundledOutput("back", colors.orange)
print("Waterpumps engaged")
sleep(2.0)
shell.run("rom/programs/custom/refinerycontrol.txt")
elseif input == "6" then
shell.run("exit")
elseif input == other then
print("Please type the number")
sleep(2.0)
shell.run("refinerycontrol.txt")
else print("not available")
shell.run("rom/programs/custom/refinerycontrol.txt")
end

I hope you can help me :mellow:/>/>
Mattzz #2
Posted 11 March 2012 - 11:00 PM
something to do with your use of "print" maybe?
also try "help rs" and look at the commands
its prolly just that you need to use rs.getBundledInput or rs.getBundledOutput
can you make what your saying a bit clearer (structure is a bit off(i get the gist of it though))
happy2pester #3
Posted 11 March 2012 - 11:28 PM
Where you have this

if rs.setBundledOutput("bottom", colors.white) == TRUE then
  print("| 1. Oilpumps and refinery - ON  |")
else
  print("| 1. Oilpumps and refinery - OFF |")
end

Instead try this - I think you're using the wrong command.

if rs.testBundledInput("bottom", colors.white) == TRUE then
  print("| 1. Oilpumps and refinery - ON  |")
else
  print("| 1. Oilpumps and refinery - OFF |")
end
Mattzz #4
Posted 12 March 2012 - 12:35 AM
yeah that should work but make sure it is a lower case true
Cheska #5
Posted 12 March 2012 - 09:42 AM
Where you have this

if rs.setBundledOutput("bottom", colors.white) == TRUE then
  print("| 1. Oilpumps and refinery - ON  |")
else
  print("| 1. Oilpumps and refinery - OFF |")
end

Instead try this - I think you're using the wrong command.

if rs.testBundledInput("bottom", colors.white) == TRUE then
  print("| 1. Oilpumps and refinery - ON  |")
else
  print("| 1. Oilpumps and refinery - OFF |")
end

Thanks man, that is exactly what I was looking for!

something to do with your use of "print" maybe?

What's wrong with my use of "print"? This is in no way a hostile comment, I just want to learn ^^
Advert #6
Posted 12 March 2012 - 09:52 AM
Where you have this

if rs.setBundledOutput("bottom", colors.white) == TRUE then
  print("| 1. Oilpumps and refinery - ON  |")
else
  print("| 1. Oilpumps and refinery - OFF |")
end

Instead try this - I think you're using the wrong command.

if rs.testBundledInput("bottom", colors.white) == TRUE then
  print("| 1. Oilpumps and refinery - ON  |")
else
  print("| 1. Oilpumps and refinery - OFF |")
end

Thanks man, that is exactly what I was looking for!

something to do with your use of "print" maybe?

What's wrong with my use of "print"? This is in no way a hostile comment, I just want to learn ^^

Nothing; except that print("stuff") may be clearer to read than print "stuff". Note that this ONLY works with literal strings and table declarations:


a = "asd"
print a -- does not work
print "a" -- works
b = {}
print b -- does not work
print{} -- works

This'll work with any other function, too, but I wouldn't recommend doing it.
Cheska #7
Posted 12 March 2012 - 02:00 PM
My code is working now, but a new problem emerged. I don't know whether I should start a new thread so I'm trying it here for now.

The problem is that once I turn on one of the machines thus activate one of color outputs the signal for every other color gets lost or rather looses it output. My idea was to use toggle-switch-cables from redpower but maybe there is also a way to script this.

In short: How do I keep an color output through a bundled cable if I activate another color?
Liraal #8
Posted 12 March 2012 - 02:08 PM
function colorAdd(side, color)
local tmp=rs.getBundledOutput(side)
rs.setBundledOutput(side, colors.combine(tmp, color)
return true
end