Evan McGrath
Evan's Dev Blog 2/21 - Visual Upgrades and A Better Dialogue System
Hello everyone!
It's been a while since my last update! However, unlike my previous delayed update, this hasn't been due to production difficulties. Quite the opposite in fact! Everything is running quite smoothly right now, and until this week, there was little for me to report on unfortunately. "Random Encounter" is now running on platform, properly letterboxed and devoid of any interface issues! While far from final, I took the time to add a bit more visual flair to the game and start cleaning up some of the UI.

I've also added a variety of new spells to the game. Ever since my issues with the Paralysis effect, the Effect system has been quite stable. Players now have moves that can buff their own attack, defense, and speed, lower the target's stats, and most importantly, heal! The player can even click and hold to display more information about the spell.

With all these visual changes, I wanted to correct a long standing visual bug with the dialogue system. Up to this point, each line of dialogue was encoded as a simple string. While this does work, it results in unprofessional looking behavior when a new line needs to be printed.

See how the word begins on line 1 before appearing on line 2? This is because dialogue is printed character by character and makes no accommodation for the amount of characters in the line. My previous solution checked if a space should be added in specific cases, but due to the difference in scaling for specific characters (I vs M), this would be unpredictable. Instead, we can use the built in Max Visible Characters function to solve this. In a more general case, we would set the vertex alpha of the text to 0. My previous solution can work, but would require calculation of how much space the text takes up and if that will exceed a line's width, and is wholly unneeded in this case.

With that undesired behavior fixed it came time to add articles for creatures. Previously, only a creature's name would be taken into account when displaying dialogue, but ultimately for generic enemies, we're going to want an article (ex. The Slime as opposed to Slime).

Checking for the use of an article is simple; the issues arise when it comes to using proper grammar for the inserted article. I feared having to write a disgusting function that iterates through the string and checks for the beginnings of sentences to process capitalization correctly. Though this is simple, I figured there must be an easier way to process cases such as this.
In my brief search, I rediscovered Regular Expressions (Regex). I had used Regex in a limited capacity in older projects, but this represented an opportunity to see what it could really do. My hypothetical grammar check function can be condensed into two lines of code using Regex, and it's possible they could be condensed further. Here's how it works:

To break this down: sequence is the dialogue sequencer we want to filter, placeholder is a series of characters that is to be replaced with the character's name (in this case, [user] is passed in, though [target] is used as well), and name is the entity's name with its article included accounting for capitalization (in this case, The slime). The strange character sequence in the middle is our Regex. This sequence does all the work.
The @ before the string suppresses the escape character '/' which allows it to function properly.
The parenthesis indicate a group. This group is later referred to in the replacement string by the "$1" sequence which prevents anything in the group from being removed.
In the group, we have a series of characters followed by a |. Each | indicates a group member.
^ is a character referring to the beginning of a string.
The \ indicates that the Regex function should check for the exact character given, as ., ?, and ! have specific meanings in Regex.
Essentially, this function checks for any instance where "The" in "The slime" needs to be capitalized. Next, we replace all remaining instances of the placeholder string with an all lowercase version (the slime) and we're good to go!

And there we go! Next week, I intend to talk about the status screen. See you then!