So a few months ago I started making a framework for Unity3D that lets developers add branching stories to their projects. I wanted it to be super flexible and relatively easy to use, while still offering more functionality for anyone who wanted to do more with it.
The biggest feature of my framework (which I've taken to calling "RenUnity" as an homage to the Python-based visual novel framework, RenPy) is the ability to insert commands into the dialogue. These commands control when the dialogue box appears and disappears, as well as what buttons show up and what they say, etc. Each command starts with a forward slash (e.g. /jump, /option, /mood), similarly to how commands are entered into the chat log in Minecraft.
So that's where the "slash" in the title comes from. I'll explain the other two shortly, but first I'd like to take a moment to appreciate Undertale and Toby Fox's amazing ability to somehow have great delivery in a text-based medium. It baffles me how well he can convey emotions with slight changes in character expressions and well-timed pauses in dialogue. If only I could be that good, I often think to myself. I want to give my dialogue that kind of flair, too.
I decided that I could have that kind of finer-grained control over the flow of dialogue if I wanted--all I had to do was code the dialogue box to be that way. So I did.
On top of being able to control the base speed that the text is written to the box, I added single-character commands for controlling the speed of certain words. For instance: /d would double the speed, and /h would halve it. I also had /q for quarter speed and /f for four-times speed. Pretty nifty.
But what if I want to pause between words? I added /p for small pauses, which can be chained together for longer pauses. What if I want to write an entire word instantly? I made /i do just that. What if I want text to backspace itself after it's written? Got some /b for that action. Who knows if I'll ever actually use it, but it's there if I ever want to.
I was so excited about the control mechanisms I added into my nifty little dialogue box that I decided to just mess around with them a bunch--and then I realized the fatal flaw in my design: I used forward slashes for everything, even though there are two different parsers. Whoops. That'll inevitably break something unless I figure out a way to change it, I thought. Gotta find another character to use for these commands instead of a slash. But what character could I possibly use? There's such a large number of special characters to choose from! How am I supposed to make such a difficult decision?
(It's probably very obvious now that I'm stalling for dramatic tension. You can very clearly see where this is going, because you read the title of this post--unless you didn't due to some bizarre vendetta against blog post titles. That would be a super weird vendetta, though; you should probably just let that one go.)
Ladies and gentlemen, I implore you to find a circumstance where I could possibly turn down using my favorite character for the purpose of replacing the forward slash. What's my favorite character, you ask? Why, that should be pretty obvious--the hashtag!
What? You call it a "pound sign"? That's a dumb name. It prefers being called a "hashtag", and I'd thank you to respect its wishes.
So okay. Now you know about the "hash commands" and "slash commands" I implemented. But what about the "tag" part of the title? This is where it starts to get fun (unless you're not lame like me and you don't think formatting text is fun).
If you've ever programmed in html, or even written a word document, you probably know about bold-facing and italicizing, as well as changing the size and/or color of your words. I was led to believe that text boxes in Unity3D were not capable of such things, and had accepted that I would not be able to do the Zelda-esque technique of "this word is a different color and is therefore important".
I accepted this, that is, until yesterday.
Yesterday I learned that my wildest dreams were, in fact, possible. I could have my syntax-highlighted cake and eat it, too. Unity3D text boxes have the ability to support "Rich Text", which is just a fancy way of saying you can use html-style tags (oh snap, there it is) to bold-face and italicize individual words instead of formatting the entire text box as a whole.
Unfortunately, because of the nature of my dialogue box as it was, I couldn't just immediately add html tags and think everything would turn out exactly as I wanted. In order for an html tag to work, it needs to be in a pair (e.g. <i>this text would be italicized</i>). Because the "</i>" wouldn't be added until the entire phrase had been written, the words wouldn't be italicized until the very end.
After some fancy computer sorcery, I wrote a system that allows for each character to be written exactly as it would appear when all the tags are in place (this involves me taking the tags out at the start and putting them back in later when I need to, which is kind of a hassle, but ultimately worth it).
So yeah. If you want to see the specifics of what my code looks like, you can go to my GitHub page and check it out. If you want to stop reading my ramblings about text formatting, well, you're in luck! This is the end of this blog post.
Thanks to everyone who stuck it out until the end, and thanks in advance to anyone who leaves a comment letting me know what they thought (unless you were mean about it)! I'll probably be getting to the topics I mentioned in my first post next time--I just did a really cool thing yesterday/today that I wanted to share, so I wrote this, instead.
Until next time!
--JBird
--JBird
No comments:
Post a Comment
Want to tell me something? I would say I'm all ears, but that'd be a gross exaggeration of my physical appearance.