🤑 Indie game store🙌 Free games😂 Fun games😨 Horror games
👷 Game development🎨 Assets📚 Comics
🎉 Sales🎁 Bundles

Weird behaviour of STMTextInfo for events at end of string

A topic by Jakub Wasilewski created 10 days ago Views: 19 Replies: 1
Viewing posts 1 to 2

I'm using custom events to set up links inside my text. I'm using markup like "<e=link:start>foo<e=link:end>" to trigger events so that I can get coordinates and generate a proper collider. I've hit a snag, though - this does not work at the end of the string.

If you trigger a custom event at the last position in the string, the STMTextInfo object passed to the callback has invalid data in it. 'pos' does not reflect where the string actually ends, and all the XXXVert properties are filled with NaN vectors.

I understand that there is no actual next character at the end of the string, but maybe STM could pretend there is a 'virtual' zero-width character there, so that all these properties are usable when an event is placed at the end of the string?

Adding a zero-width space to strings right now as a work-around, but would really prefer this to be fixed.

Developer (Edited 2 times)

Oof, good catch. Yeah, when custom events are invoked, it references the "info" array, and the "tacked-on" events as I call them have an info with no matching character in the string to reference.

You're right, a zero-width space added to the end of "hyphenedText" should be the easiest way to fix this.

if(info.Count > myText.Length){
    //add extra char to myText for tacked-on event
    myText += "\u200B";

I added this code to the end of the ParseText() event, right before return is called, and everything seems to work fine, now!