Whatchu talkin’ bout Willis?

I’ve spent most of my weekend trying to sort out a system for parsing text from an Ink script to display paragraph-by-paragraph when the user presses a button.  Easy enough in itself as the Unity integration allows you to call each individual line that makes up the body of the current ‘continue’ (i.e. all text before the start of the next choice list).  However, it becomes more problematic if the text is longer than the text view area.

What I essentially wanted was the following:

  1. If the line of text is shorter than a defined length (a variable found through trial and error) display that
  2. If not then split it into smaller chunks…
    1. If the text has a defined punctuation (. ? or !) then split it there
    2. If not…
      1. If there’s a comma roughly halfway through replace the comma with ellipses and split there
      2. If there’s not,  do the same but with a space

Again, doesn’t sound particularly problematic but had issues with trying to get it to work.  Such as:

  1. For some reason I went through this whole process of taking the text Unity/Ink automatically supplies and split it up myself initially, which took a fair while figuring that out.  It’s only when I started writing this I realised I could take the Unity/Ink currentText call and dump that into the string list instead.
  2. It took a while to figure out how to break up longer text based on punctuation and keep that punctuation in place (the Split function I was using was removing the character it was splitting on).
  3. Likewise, figuring out how to break long strings into shorter ones using ellipses took a while
  4. Had to figure out how to work around ‘unwanted’ punctuation.  The one that cropped up in my example text (entirely coincidental it was in there in the first place) was an e.g. which it was reading as being a full stop.  Similarly, don’t want it picking up duplicate or mixed punctuation (??, !! or !?!?).  Turns out the easiest way is to temporarily replace it with some dummy text and replace it back again.

When I write it down like that it makes me realise how little I know as that seems simple yet took me a fair while!

There’s still more to do though:

  1. Get the flow working as per the user input.  At the moment any non-broken line is printing when you hit enter, but anything broken up prints all the parts at once (mostly for me to test it is breaking up correctly)
  2. Currently doesn’t account for if a broken piece of text using ellipses is longer than two screens (for the purpose of testing I’ve just split it into two chunks, but in reality it could be more if its a very long piece of text with no sentences).
  3. Need to test with different text.  I set up a test text script, but want to check it is working properly using some more test scripts.
  4. Allow flexibility of the line length value depending on language
  5. Need to allow for a dictionary of sorts for the temporary text replacements and have Unity run through that and replace as/when it finds them, rather than just a series of hand-written replace functions at the moment.
  6. Ideally also have some way of knowing if punctuation is strung together (!?!?!) without having to write each possible variation

I’m sure there’s probably an asset or something I could have downloaded to do all this, although having a quick look most of the things I could find seem to predate Unity’s new(ish) UI system.  Although I didn’t look too hard.  Plus they’re not designed for Ink (although undoubtedly I would have been able to middleware it myself).

However, it was educational (if at times painful) so I’m happy I stuck with it.  Just need to finish it off, preferably before I go back home for Christmas.

Scroll To Top