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

Trying to add/subtract colors from a set of bundled cables. Help ;0_0

Started by S16IceMan, 28 August 2012 - 04:25 PM
S16IceMan #1
Posted 28 August 2012 - 06:25 PM
(This is on my tekkit server that I host)

Ok so here's what I'm trying to do…

I've made a factory that is running all of its red power from a single CC computer with a bundled cable in the back. I need help with a lua code that can add or subtract a single or group of colors that are currently on/off without having to write in every single possible combination of colors.

For example, I currently have the lights inside the factory running off of the white cable, the pumps sending items to macerators and electric furnaces running off of the magenta cable, and a light green cable that powers the pump leading to an automatic crafting table.

My goal is to have a user interface that will independently run a single color of cable without having to turn off the other colored cables, similar to levers but from a single point.

Here's an example of what I'd like the interface to look like… (this much I can do on my own)

Welcome, IceMan – i used a roaming profile program as a start up
IceNet Factory Interface
Iron Machines Interface [1]
Toggle iron ore pump [1]
Pumps are currently ()
Toggle macerator and induction pumps [2]
Pumps are currently ()
Toggle refined iron pump[3]
Pumps are currently ()
Back [4]
Cobble Generator Interface [2]
Toggle cobblestone generator timer [1]
Timer is currently ()
Set cobblestone timer increment [2]
Current timer increment is () seconds
Back [3]
Iron Furnace Table Interface [3]
Toggle iron pump [1]
Pump is currently ()
Toggle furnace pump [2]
Pump is currently ()
Toggle ironfurnace pump [3]
Pump is currently ()
Back [4]
Factory Door Interface [4]
Doors are currently ()
Open doors [1]
Close doors [2]
Back [3]
Lighting Interface [5]
Lights are currently ()
Turn on Lights [1]
Turn off Lights [2]
Back [3]
Master Interface [6]
Power on [1]
Power off [2]
Exit [3]
Any advice from the pros?
krazyjosh1234 #2
Posted 28 August 2012 - 06:55 PM
I'm not sure about the interface, but I believe you can activate different wire colors like this:

Adding
c = rs.getBundledInput("back")
rs.setBundledOutput("back", colors.combine(c, colors.COLOUR))
Subtracting
c = rs.getBundledInput("back")
rs.setBundledOutput("back", colors.subtract(c, colors.COLOUR))
S16IceMan #3
Posted 28 August 2012 - 06:59 PM
S16IceMan #4
Posted 28 August 2012 - 07:11 PM
but how could I use that code in the means of an on/off command executed by a 1 or 2?

More specifically, how can I use a read() command in place of the (c, colors.COLOUR) ?
krazyjosh1234 #5
Posted 28 August 2012 - 07:15 PM
Not to sure what you mean there, but would this help:

local input = read()
if input == 1 then
  print("Doing something")
  c = rs.getBundledInput("back")
  rs.setBundledOutput("back", colors.combine(c, colors.COLOUR))
elseif input == 2 then
  print("Stopping something")
  c = rs.getBundledInput("back")
  rs.setBundledOutput("back", colors.subtract(c, colors.COLOUR))
else
  print("Confused")
end
S16IceMan #6
Posted 28 August 2012 - 07:17 PM
Ok, this solved my problem. Thank you so much. It helps a ton :D/>/>
krazyjosh1234 #7
Posted 28 August 2012 - 07:18 PM
You're welcome, happy to help. :D/>/>
krazyjosh1234 #8
Posted 28 August 2012 - 07:24 PM
Ah, I didn't see that read() colour part. Heres an amendment:

print("Input colour in the format of colors.COLOUR: ")
local inputc = read()
print("On or Off?")
local input = read()
if input == "On" then
  print("Doing something")
  c = rs.getBundledInput("back")
  rs.setBundledOutput("back", colors.combine(c, inputc))
elseif input == "Off" then
  print("Stopping something")
  c = rs.getBundledInput("back")
  rs.setBundledOutput("back", colors.subtract(c, inputc))
else
  print("Confused")
end

Hopefully that works.
wolf2k12 #9
Posted 28 August 2012 - 11:01 PM
Just so you know, the wire colors are addressable by powers of 2. you can use the function
<code>
function expo ( number )
if number == 0 then
return 0
else
return ( 2 ^ ( number - 1 ))
end
end

</code>

to use plain numbers and address each cable by number.

I use this in my pump controllers script. if I tell it to start wire 1 (which is white) it passes expo(1) to my controller. if I tell it to start wire 16 (which is black) it will pass expo(16) to my controller. expo(16) = 32767.

Haven't figured out the code yet to add multiple on's on the same input line but you can use the return from expo() in the colors.combine() and colors.subtract() functions.

Hope this helps you.