Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics

Counting lines and words in STM

A topic by Rekize created Nov 25, 2018 Views: 44 Replies: 3
Viewing posts 1 to 4

May I ask is there a way to count the words, line, and words in a line in STM by script?


Yes, there are some hidden values in STM that should give you these values, but you can do some tricks with string.Split, too!

"stm.lineBreaks.Count" should give the amount of lines. "stm.hyphenedText.Split('\n').Length" should also return the same value.

"stm.hyphenedText.Split(' ').Length" should give the amount of words, by counting the amount of spaces in the final text shown.

Words in a line is a bit trickier, but you can use the info from the lineBreaks list (this list contains the indexes of line breaks in hyphenedText) to do this.

This is some really rough untested code, but something like this will give the amount of words in the first line of text:

string line1string = stm.hyphenedText.Split('\n')[0]; //get all text before first linebreak
int line1wordCount = line1string.Split(' ').Length;

I hope this helps!

(1 edit)

Great, this helps a lot! Thanks.

I found it especially useful when the different lineBreaks information stored in text and hyphened text are used together :)