Dynamically change text color between letters

Hello…

I’m trying to make this word guessing kind of game
i want the player to form a word based on a letters above

when currently typing (text below), and the player typed the key letters above, i want the bbcode text to change colors to green, but only the key letters, in this case its only “AS”, and the rest letters are default white.

just at a quick glance, youll have to compare texts, you can do conditions like “if text X contains X Word”

then do the action, change BBtext to change to green, or something along those lines

Just an idea

1 Like

To change the color of the letter you put them in
[color=#hexColor]colored text[/color]

Like
[color=#FF0000]this text is red[/color]

Say you want the PP in APPLE to be colored.
It would be
A[color=#hexColor]PP[/color]LE

You can use several of the text manipulation expressions and a while event to replace the PP with [color=#hexColor]PP[/color] or you could use the RegEx extension. It has a replace function.

I tested it with a BB text and text input. I used a LastText scene variable to prevent it from being triggered on every frame. This might need some extra checks to prevent weird things like maybe an empty text or something. You need to plan for unexpected results.

The flags for the RegEx are “gi”, you can add or remove them. The g is for global. It matches all occurrences of the search string, the i flag ignores the case.

I kind of tested this backwards. The alphabet string is the source it would be what the user was typing, the input box was the letters to be searched for.

The syntax for search is text to search for like “PP”, the flags, the text that the user types like apple, the replacement text which would be the “PP” inside the color code.

This is more like your game.

Search for PP in the input box and replace with PP surrounded by the color code. You would replace PP with the variable that holds the letter to change the color of. That would be in both places where the PP is. The input object would be replaced with the variable that contains what the player typed.

That’s better. I’m not really familiar with RegEx.

(search text, flags, text to be searched, replacement text)

1 Like

just as a small note, if you want to use just basic colors, you dont have to specify using #longnumber, you can just do:

[color]blue[/color] or [color]green[/color] just an example

2 Likes

thankss!, both of you

Medal_lGdemTtRX0

it worked perfectly

1 Like