Skip to content
Kiminaze edited this page May 1, 2022 · 7 revisions

All elements inside the ContextMenu use the Color class.

Using predefined colors

The Color.lua file comes with a table with predefined named colors. You can simply access the Color.lua file to see all available colors or add new ones.

local red       = Colors.Red
local green     = Colors.Green
local lightBlue = Colors.LightBlue

Should you accidentally misspell a color or use a name that is not inside that table, instead of throwing an error, the script will default to a magenta/pink color that is known in many games as the "missing texture" color.

Color(r, g, b, a)

Create a new color from its RGBA channels (red, green, blue, alpha) (range is from 0-255). Should you not pass parameters to the function, it'll simply return a black color.

Parameter Type Range Default Description
r integer 0-255 0 The red channel of the color.
g integer 0-255 0 The green channel of the color.
b integer 0-255 0 The blue channel of the color.
a integer 0-255 255 The alpha channel of the color.
local red   = Color(255, 0, 0, 255)
local green = Color(0, 255, 0, 255)
local blue  = Color(0, 0, 255, 255)

Other possible combinations:

local black = Color()           -- same as Color(0, 0, 0, 255)
local red   = Color(255)        -- same as Color(255, 0, 0, 255)
local green = Color(0, 255)     -- same as Color(0, 255, 0, 255)

Parameters

After a color has been created, you can easily change its values one by one as well:

-- create a color first
local myCol = Color(255, 0, 0)

-- change the RGBA values
-- this results in the same as Color(147, 50, 4, 150)
myCol.r = 147
myCol.g = 50
myCol.b = 4
myCol.a = 150

Alternatively you can also return a new color with a changed alpha. This way you can still keep the old variable as needed.

-- create a color first
local red = Color(255, 0, 0)

-- return a new color with a different alpha value
local seethroughRed = red:Alpha(150)

Color in text form

If you need the color in text form, you can just use the tostring function.

local colorText = "My color: " .. tostring(Colors.Red)
print(colorText)
> My color: Color(255, 0, 0, 255)

Clone this wiki locally