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

How to set a color from an array.

Started by TNT_Nolan, 18 May 2016 - 06:48 PM
TNT_Nolan #1
Posted 18 May 2016 - 08:48 PM
Hello, I am trying to make it so I can set a background color from a string.

Heres an example.


colortable = [colors.red,colors.blue,colors.white]

term.setBackgroundColor(colortable[1])


A post would be appricated.

Thanks,
Nolan
Chickenbreadlp #2
Posted 18 May 2016 - 09:00 PM
Just replace the [] with {} and you get a table. That sounds just like you wanted

colortable = {colors.red,colors.blue,colors.white}
term.setBackgroundColor(colortable[1])
Bomb Bloke #3
Posted 19 May 2016 - 01:44 AM
Truth be told, the keys used to define the colours in the "colours" table are already in the form of strings.

term.setBackgroundColour(colours.red)

-- ... is the same as:

term.setBackgroundColour(colours["red"])

-- ... which is the same as:

local myCol = "red"
term.setBackgroundColour(colours[myCol])