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

Bundled Cables Help

Started by cameron2134, 31 March 2013 - 08:28 AM
cameron2134 #1
Posted 31 March 2013 - 10:28 AM

Hey,


I'm pretty new to ComputerCraft, just started playing around with it today. I've made a couple simple programs such as a password protected door, and a computer that controls lights, however what I have been trying for the past hour or so is a computer to control all the machines in my factory. It's pretty much done - I just can't figure out how to "add up" the bundled cable values, for example, I have 3 output cables: white, red, and orange. I can turn white on, but when I turn red on, white turns off, because the value changes to 16385 instead of 16386 for both white and red.


I know what I have to do, make it so that if white cable is on, it adds one to the red cable when I turn it on, and if white and red are on, it adds 16386 to the orange cable, so all 3 turn on. Only thing is I have no idea how to do this in Lua. I think it might involve using variables, although I am still not sure.


If you could help it would be much appreciated, so close to finishing this and now I'm stumped right at the end


Code: http://pastebin.com/iAwFCbyJ


The "state" variable is when I tried to use variables to add them but I could not get it to work.
Engineer #2
Posted 31 March 2013 - 11:11 AM
Here all are the color values: http://computercraft...iki/Colors_(API)

Here is a sample code:

local red = 16384
local white = 1
local orange = 2

--All the colors  at once:
rs.setBundledOutput("right", red + white + orange)
-- You can figure out that part yourself I presume ^

--lets turn if off
rs.setBundledOutput("right", 0)

For the turning off part, you entered "0", wich is an string.
0 is an integer
5.0 is an double

In this language we dont make difference between doubles and integers. We can simply do without trouble: 0 - 0.5.
But a string is text, you can convert this with the tonumber function. Usage:

local var = "1"
local strVar = tonumber(var)

-- OR

local strVar = tonumber("1")

We can do this also vice versa, with tostring.

I hope you understand this, and if you have questions please ask further on this thread.
Dlcruz129 #3
Posted 31 March 2013 - 07:59 PM
rs.setBundledOutput(side,colors.combine(rs.getBundledOutput(side),colors.red))

This will add red to the current total output.
theoriginalbit #4
Posted 31 March 2013 - 08:09 PM
rs.setBundledOutput(side,colors.combine(rs.getBundledOutput(),colors.red))

This will add red to the current total output.
you're missing the side parameter on the getBundledOutput
Dlcruz129 #5
Posted 31 March 2013 - 08:11 PM
rs.setBundledOutput(side,colors.combine(rs.getBundledOutput(),colors.red))

This will add red to the current total output.
you're missing the side parameter on the getBundledOutput

You didn't see nuttin' :P/>

This must be my punishment for coding on a phone late at night.
cameron2134 #6
Posted 01 April 2013 - 07:26 AM
Thanks for the help, I managed to "almost" get it working. I changed the code a bit, to see if it would work. However, for some reason the colours do not add up, even though in the code they are supposed to if the other system is running. It just turns the other one off. E.g. the Refinery is online, when I go to turn the Recycler online, it will turn the Recycler online and turn the Refinery off..I spent a while looking at the code, and it looks as if it should work properly, but I must be missing something.

Code: http://pastebin.com/DgEdXTnW
cameron2134 #7
Posted 05 April 2013 - 11:35 PM
Bump
PixelToast #8
Posted 06 April 2013 - 04:50 AM
your declaring numbers as strings, remove the ""s around numbers
remiX #9
Posted 06 April 2013 - 05:01 AM
Yeah, change white = 1

You can also use the colour api
white = colours.white
-- or colors.white :P/>/>