Changing the colour of specific sections of a string

Hello!

I’m TeaAndCopy, I had come up with this idea quite a while ago as I am sure many of you have also thought about this too. Have you ever made a text label but want the colour of the text to be different from another part of it? Well currently, unless you use external systems or use multiple labels, it’s not possible to do this.

I’m therefore, keen to see this make its way into ROBLOX so that developers can make their text unique and colourful really easily.

How useful would it be?

I’d say it would be very useful, even if you wanted to make something like this in your game but have the ‘Filtering Enabled’ section to be green. Doing this now would be extremely difficult. Especially if you wanted to limit it to 2 strings.

“Game 1 | Filtering Enabled | Ver 1.2.0”


Please post your thoughts & opinions below. All feedback is welcome!

-Tea

31 Likes

Already suggested:

2 Likes

I think this would be a wonderful addition to Roblox.

This could be used for many things on chat guis. For example, we could make ranks in chat really easily by just adding a different color text at the beginning of the label. This could be used for things like staff and VIP.

One question I have for you is how would we set the colors of the string? Would it be like html inside the string or would it be a separate property.

1 Like

As much as HTML would be a great thing. ROBLOX simply doesn’t use it. In addition, new developers may not want to have to learn what HTML is to understand why it works.

I think there could be a way to use colours by using string patterns. For example if you wanted to add a ’ to a string that uses ’ at the start of it, for example ‘Don’t’ You use a \ to let the script know to not end the string.

You could also make a string.color() to tag each string as a color. I.e

text = string.color(‘Really red’, 'Hello, ')…string.color(‘Really black’, ‘World!’)

The only difference between string.color and <color></color> (in either case, users have to learn new syntax) is that one is also used elsewhere, which doesn’t make it harder to use – in fact, some would already know how.

1 Like

string.color matches with the rest of Lua. HTML add-ons just confuses things, not to mention it doesn’t fit in with the rest of the code. Besides, if we allow this small use of HTML, this would open up a whole can of worms of people wanting more HTML.

The syntax doesn’t have to be relearned, only the format.

1 Like

A new sequence type would fit here,
gui.Text = "Hello world
gui.TextColors = TextColorSequence.new({6}, {Color3.new(1, 0, 0), Color3.new(0, 0, 1)})
where each number indicates the character index in the text where the color changes to the next value in the list of colors. This would be a property of GUIs that have text.

3 Likes

How would you concatenate multiple sequences to one ui element?

1 Like

I’m not necessarily a fan of that because it’s only for text color. I would prefer something that works universally e.g. bolded/underlined segments of text in addition to color. Maybe even font/font size.

4 Likes

We could add a whole range of string manipulations,

string.color

text = string.color('Really red', 'Hello, ')..string.Color('Institutional white', 'World!')

string.size

text = string.size(18, 'Hello, ')..string.size(Enum.FontSize.Size10, 'World!')

string.bold

text = string.bold('Hello, ')..'World!'

string.underline

text = string.underline('Hello, ')..'World!'

string.italics

text = string.italics('Hello, ')..'World!'

string.strike

text = string.strike('G\'day, ')..'Hello, World!'

string.transparency

text = string.transparency(0.5, 'Hello, ')..string.transparency(0.1, 'World!')

I don’t see an issue with making these a thing. Sure you’d have to learn the format of them however I don’t think it would that hard considering that every other string manipulation uses the same/similar format.

19 Likes

Support. Would be very helpful.

1 Like

API bloat – not a good idea. No need to reinvent the wheel when we already have a solution that’s already used elsewhere. Not wanting to learn sounds like a personal problem – you’ll always have to learn new things in tech, so you’ll eventually have to get used to it.

3 Likes

What would that solution be? I’m not posting this because ‘I don’t want to learn’ I’m posting it as one of the main ideas with feature requests is to make the lives of developers easier. Just because someone made the wheel, doesn’t mean we shouldn’t make it better, i.e add a tire to that wheel.

Markup

3 Likes

Mhm could be something like https://docs.unity3d.com/Manual/StyledText.html which uses a toggle to enable parsing of markup text.

2 Likes

If we were to include markup rather than the format I suggested, we could have two types of strings. One that included the use of markup and one that didn’t. This would allow developers to use the ‘markup text commands’ if you will, without it actually changing the text. I.e

markupString = "  **Bold text**  " -- ** makes text bold and so it isn't seen in the string
normalString = "  **Normal Text**  " -- This type of string doesn't include markup and so ** doesn't affect the string

What would you need another string type for though? Marked-up strings would only ever be useful in UI since you show them to the user there, so a toggle on UI classes with a text property seems more suitable (rather than adding a whole new datatype that behaves identical to regular strings apart from displaying them).

4 Likes

A toggle does sound better.

HTML or a variant would be nice. It takes around 5 mins to learn how to use HTML.

We could also do BBCode.

Made this today - fun stuff, but surely a builtin RTF text UI element would be nice to have. Though for this thing, the most work was actually the Lua syntax highlighter more than the displaying of information itself.

For most of the part, I miss the ability to make any font bold, italics, and the possibility of text shadows / text outlines. You can do a bunch of stuff already with TextLabels, just not as easy as i.e. with HTML.

25 Likes