How do I store a text into an array each letter on it's own

Get help using Construct 2

Post » Sun Jul 13, 2014 8:39 am

Hi!

I need to write text in which each character can be separately colored. I found out that the Tag Text plugin can do that.

The way Tag Text works is that you give the letters you want to color a tag by giving them a class. For example if I wanted to color the letter "t" in the sentence "My example sentence" I would have to type it like this:

Code: Select all
My example sen<class="tagged">t</class>ence.


I need to choose which letters to color dynamically based on variables. How should I approach this problem? My initial thoughts are that I should maybe store each letter of the sentence separately in an array so that I can loop through them and add the class when needed.

Is it possible to take a sentence and automatically store each letter in an array? I'm trying to avoid having to put each letter by hand to it's place in the array.

Any thoughts are welcome!
B
9
S
1
Posts: 97
Reputation: 715

Post » Mon Jul 14, 2014 2:57 pm

Phew, I finally got it!

I will attach a capx-file in which we first take a string and store each letter in an array. Then we loop through the array and manipulate the contents based on variables. Finally we output the array back to text and use Tag Text to color specific letters of the sentence!

Very cool! :)
You do not have the required permissions to view the files attached to this post.
B
9
S
1
Posts: 97
Reputation: 715


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, Bootfit, jorgmaquoi, OddConfection, Rable, unicornspitfire and 10 guests