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

[Lua][Question] How to create an array of colors?

Started by Backplague, 14 April 2012 - 02:25 PM
Backplague #1
Posted 14 April 2012 - 04:25 PM
Since im trying to detect what RedPower inputs have changed, i have to store the current ones in a list and compare the next colors to the previous colors.
Luanub #2
Posted 14 April 2012 - 10:39 PM
Use the colors api. Type help colors of help redpower for more information, but it would look something like..


to add colors to the array
c = colors.combine(c, colors.white, colors.red, etc... etc.. etc... )

to remove
c = colors.subtract(c , colors.white, colors.red, etc... etc... etc.. )

to utilize with the rs commands
rs.setBundledOutput("side", c )

I haven't tried it, but you should be able to use the var c in other statements so hopefully this helps you.
Wolvan #3
Posted 14 April 2012 - 10:43 PM
use the colors.combine function. I used so just go ahead and ask.
@Cloudy c is a combination of those colors so if you would write

c = colors.combine(colors.red, colors.green, colors.white)
rs.setBundledOutput(c, true)
red, white and green would turn on and every color else turns off
Luanub #4
Posted 14 April 2012 - 10:57 PM
Ya I guess I should have elaborated a little more on the syntax.

For the subtract you need to place the colors var as the first argument so it knows where to remove from

With combine if you do not place the colors var as the first argument, it will create a new list with only the colors listed.

If you use the color var as the first argument it will add the listed colors to the already existing list.
Backplague #5
Posted 15 April 2012 - 10:33 AM
How can i then go through every color in the set? For loop doesn't seem to work.
Cloudy #6
Posted 15 April 2012 - 04:47 PM
If I want to iterate through every colour in the list, I do this:

for k, v in pairs(colors) do
  if type(v) == "number" then -- we do this check as there are some functions in this table too.
	-- k is the name of the colour, v is the value - do your stuff here!
  end
end
Backplague #7
Posted 30 April 2012 - 09:41 AM
-nevermind, solved-