Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get 19BE7278 to a brickcolor or a color3?

Asked by 10 years ago

19BE7278 is just an example, it can be a lot more. Don't know the official names for these.

Or if anyone knows how to do it before I got that value;

function GetColor()

local PlayerColours = {

BrickColor.new("Bright red"), BrickColor.new("Bright blue"), BrickColor.new("Earth green"), BrickColor.new("Bright violet"), BrickColor.new("Bright orange"), BrickColor.new("Bright yellow"), BrickColor.new("Light reddish violet"), BrickColor.new("Brick yellow"),

}

local GetNameValue = CurrentText

function GetChatColour(Name) return PlayerColours[GetNameValue(Name) + 1] end

function GetNameValue(Name) local Length = #Name local Value = 0 for Index = 1, Length do local CharacterValue = string.byte(string.sub(Name, Index, Index)) if (Length - Index + 1) % 4 < 2 then Value = Value + CharacterValue else Value = Value - CharacterValue end end return Value % 8 end

return GetChatColour end

Later on

NewColor = GetColor() print("1") print(NewColor) print("2") print(NewColor.Color)

2 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

I'm assuming you mean HEX RGB colors? Like what are used in CSS for styling things?

If you have a sequence that is 8 long, it's most likely RGBA or ARGB (A being "alpha", or opacity; 1 - transparency = alpha). Color3's / BrickColor's don't support alpha so in this context it would be difficult to do that..

Where for instance #87CEFA is X11's "Light sky blue"?

Lua has a tonumber function which accepts a base.

function hexToColor3(hex)
    if hex:sub(1,1) == "#" then
        hex = hex:sub(2);
    end
    if #hex == 3 then
        hex = hex:sub(1,1):rep(2) .. hex:sub(2,2):rep(2) .. hex:sub(3,3):rep(2);
    end
    local R = tonumber(hex:sub(1,2),16);
    local G = tonumber(hex:sub(3,4),16);
    local B = tonumber(hex:sub(5,6),16);
    return Color3.new(R/255,G/255,B/255);
end

In the future, use the Lua button to format your Lua code so that it is reasonable to read.

0
Sorry, will do. I'm new. vlekje513 0 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
function hexToColor3(hex)
    if hex:sub(1,1) == "#" then
        hex = hex:sub(2);
    end
    if #hex == 3 then
        hex = hex:sub(1,1):rep(2) .. hex:sub(2,2):rep(2) .. hex:sub(3,3):rep(2);
    end
    local R = tonumber(hex:sub(1,2),16);
    local G = tonumber(hex:sub(3,4),16);
    local B = tonumber(hex:sub(5,6),16);
    return Color3.new(R/255,G/255,B/255);
end

attempt to index local 'hex' (a function value)

Which I called like;

NewColor = GetColor()
NewColor3 = hexToColor3(NewColor)

NewColor is the hex.?

0
Please edit your question to format your `GetColor()` function... BlueTaslem 18071 — 10y
0
How? and what? vlekje513 0 — 10y

Answer this question