How to write an expression with an 'or' selector for text

Hi - I’m wanting to write a condition that changes the text colour based on the first letter of the string. I can get it to work using StrAt(“a”, 0) to change for words starting with “a” but I don’t want to write a condition for every letter of the alphabet. I’ve tried StrAt(“a|e|i|o|u”, 0) but no joy.

It’s probably simple, but I can’t find it in the documentation.

Hi,
You want one different colour for each different letters? Or one colour for a group of letters, like one colour for vowels?

Btw, your condition should be a “compare 2 Strings” condition :
StrAt(VariableString(mytext), 0) = “a”

Right? (first parameter of StrAt is the main string)

The expression you wrote above returns always “a” since it takes the first letter of string “a”.

Hi yes if it starts with a vowel one colour a consonant another colour. Yes, I’m using the compare text condition. It’s all working, I just don’t want to write a condition for every letter of the alphabet.

You could search for the first letter of your word among a string that contains all vowels.
Use the “compare 2 numbers” condition :

StrFind(“aoiue”, StrAt(VariableString(mytext), 0)) =/ -1

(Note that gdevelop is case sensitive.)

1 Like

I was going to suggest using the regular expressions extension, but @Bluzima’s suggestion is a lot simpler.

1 Like

I should definitely take a look at this extension… I often use text manipulation, so yeah, it could make things easier for me

This is brilliant. You are brilliant. Works a treat - thank you very much!

3 Likes