Getting markers from dialogue line (String parsing)

Hey,
I am creating dialogue system for my game and I am wondering how should I approach one thing.

I would like to create parser which changes dialogue parameters based on the markers in the string e.g.

“Hey! [w1] You changed since the last time we have seen each other. [e2] [s2] I mean… [w1] In a positive way!”

where:
[w1] means Wait 1.0f,
[e2] means Display expression 2

I would like to create a Dictionary<int, Marker> where “int” is a indexOf marker and I am wondering what would be the most optimal way to do it.

The index should point the the place in message without markers (that means after parsing the dialogue line should be “Hey! You changed since the last time we have seen each other. I mean… In a positive way!”.

My idea is to (in pseudo code):

for character in fullMessage:
    find index of "[" in fullMessage
    find index of enclosing "]" in fullMessage
    put in dictionary found above index of "[" and marker
    remove marker (the whole "[w1]") from the fullMessage
    adjust loop (e.g. iteration index) to accomodate string length change

I am sure this will work but it just does not seem to be the “cleanest” solution. Any suggestions how differently I could approach the parsing?

One suggestion is to look into TextMeshPro. TextMeshPro already has a tagging system built in for it’s own tags, but what is nice is you can add your own tags into it. If you do that, TMP will hide these tags from the rendered text even though they still exist in the actual string.

Just a thought.

1 Like

In that case I definitely need to check TextMeshPro :). Thank you!

No problem. I used the same thing for a client project and it worked really well. TMP is pretty clean and flexible and you can do some extra stuff with it that the normal Unity Text can’t do. Hope it works out for you.