How do I colourize all the words in a string variable which contain a particular letter?

0 favourites
  • 6 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I am trying to get Construct 3 to colourize all words in Global String "Variable1" which contain the letter "ि" and are seperated from each other by whitespace,into red colour but currently I am able to colourize only a single letter by using these two actions and expressions-

    1.Set Variable 1 to replace(Variable1,ि,"[color=#ff0000]ि[/color]")

    2.Set Text to left(Variable1,396)

    ,and so can anyone tell me how to colourize entire words in Variable1 which contain the letter "ि" and then render them highlighetd in the Text Object

    Thanks.

  • (For some reason I can't write "ि" correctly, so let's say it is "f")

    If I understand correctly, you have Variable1="word1 f word2 f word3" and you want to make "word1", "word2" and "word3" colorized?

    What you are doing now is that you are replacing each "f" with a colorized "f". You are colorizing the "f", not the words.

    You could take a look at the "tokenat" function, which you can use with a System:For loop event to split Variable1. Then you can replace each "word" with a colorized version. It will be something like:

    1- tempVariable = tokenat(Variable1,"f",loopindex)

    2- Variable1 = replace(Variable1,tempVariable,"[color=#ff0000]"&tempVariable"&"[/color]")

  • Soul3 can you please tell me how to use the spilt "System:For loop" event to split all the individual words of Variable1 and can you also please tell me how does the loopindex expression works,Thanks.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sure!

    Add a new event, choose "System", then "On Start of layout".

    Click B while selecting this event, to add a sub-event.

    Add a new event, and choose "System", then "For".

    The rest is easy, so I will show you the final result instead:

    Try to play around with this to fully understand it :)

    Say Variable1 is "word1 f word2 f word3".

    First we need to know how many "word"s are in there. That's why we use tokencount().

    Then we need to get each one of those "word"s in order. That's why we use "For".

    "For" is like a counter, it starts from 1,2.. until it reaches our "word" count (in this case 3).

    The big Action on the right of "For" takes each word (using tokenat()), surround it with [color] tags and add it to Variable2.

    You will find more about tokenat() and tokencount() here. You can find more about "For" here (under the "Loop" section).

  • Soul3 can you please upload the .c3p,Cheers.

  • Soul3 can you please upload the .c3p,Cheers.

    :) https://ufile.io/wrcij9xs

Jump to:
Order by:
Duplicate Topics
Posts
Views
Last Post
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)