Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

[solved] Weird behaviour of STMTextInfo for events at end of string

A topic by Jakub Wasilewski created Jun 12, 2018 Views: 324 Replies: 1
Viewing posts 1 to 2
(1 edit)

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 (2 edits)

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!