1
\$\begingroup\$

I've implemented my own TypeWriter for text that looks like this

public static String GetWords(String text, float wordCount)
{
    float words = wordCount;
    // loop through each character in text
    for (int i = 0; i < text.length(); i++)
    { 
        if(i == text.length() - 1 && SceneHandler.lineFinished == false){
            SceneHandler.lineFinished = true;
        }
        words--;
        if (words <= 0)
        {
            return text.substring(0, i);
        }
    }
    return text;
}

I decided I wanted to do markup as well, so that means color codes and such. Problem is that the TypeWriter also goes through the color code (The [COLOR] and the [] part) so you get something like this

[
[Y
[YE
[YEL
[YELL
[YELLO
[YELLOW
*nothing*
(Actually yellow) T

Does anybody have any idea how I could fix this or approach this problem?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

While you're looping through each character in the input text, if the current character is the start of a markup block (that is, the [ character), then enter a nested loop to extract all the characters up to and including the closing token (the ]). Parse them, issue whatever instructions you need to actually turn the text yellow to the rest of your system, and then parse the next character and feed it out of the function normally.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .