String Theory
Dev log for Project Amethyst from 8/7/18 to 8/21/18
What have I been working on since the last update?
As I mentioned last update, I spent the last two weeks building a dialogue system for the game. Though I was originally inspired by an asset I found on the Unreal store, I ended up writing something completely different and original. There were two major issues I had to tackle while creating this system: separating a given string into pages that max out at the number of characters that will fit on screen, and making sure that words don’t get split up between said pages.
It took me about two and a half days to get the first iteration of this system working. I tried a couple of different approaches before settling on the one pictured below.
Basically what all this does is: 1) separates every character in the given string into a separate entry in an array, 2) takes the length of that array and divides it by the max number of characters that will fit on screen to get the number of pages needed, 3) runs a function that makes pages out of the array of characters until it hits the number of proposed pages.
As you can tell by these pictures, this system was rather complicated. Its not the most complex thing I’ve ever scripted but all the math associated with the main for loop threw me for a loop. So, saying that this is the first iteration implies that there is at least one more right? Well, even though this setup worked just fine it had one flaw: it did not care about keeping words together. As I came to tackle this issue I realized this setup wasn’t going to cut it.
So I did some digging around on the internet, through Epic’s API, and in the engine itself and found one magical node that solved all my problems. Behold:
This beauty averted what would have probably been a whole extra day of work (this is why I love Unreal btw). What it does, in a sense, is break down a string into an array of words rather than characters. This meant I could rewrite my entire system and it ended up like this:
Just in case you couldn’t tell, this is like a third of the code of the previous one and is probably 80% less complex. All the logic has been moved inside the function and the only loop is now inside as well. This one works as such: 1) split the given string into individual words, 2) loop through each word (and add back the space that got cut out by the parse) and see if it will fit into the current page, 3a) if it fits, add it in, 3b) if not, start a new page, 4) get the number of pages afterwards and start the printing
On the user-facing end, this works exactly like the previous method, but this will save me tons and tons of headache in the future. With that all squared away I can move onto the branching system (which is essentially just creating a navigable menu that sends the choice back to the dialogue sender). Shouldn’t be too hard. :/
What obstacles have I encountered?
The biggest problem these past weeks was, obviously, all the string math and logic to figure out. I even made use of the whiteboard in the classroom to try and hash out some of the logic with the help of one of the lab specialists. As I mentioned above, it took a while to get right, but that issue was eventually resolved…
What I haven’t managed to resolve yet is UI scaling. My dialogue box is all over the place in terms of scale between the widget designer, playing in editor, and playing in a new window. This is a problem because I rely on the max number of characters that fits in said box to calculate the pages, and that number is wildly different between screen sizes and scales. Ideally, I want to lock the game to a 16:9 ratio on all devices, but that doesn’t solve the varying resolution problem. For the sake of compatibility, I’ve been designing all my UI in 1920 x 1080 but my computer that I work on is natively 3240 x 2160, so if I try to test in full screen the scale gets messed up. I already wasted a couple days trying to fix this last week. Thus I think I am going to ignore this issue until I get my whole dialogue system functioning.
What's next?
As previously mentioned, next up is the branching system. After that I might work on a couple minor features for the dialogue system that I will probably need later. Then, after that, I’m not 100% sure. I might set up some more overworld interactions like pickups and other interactive objects. The next big piece I intend on tackling is the inventory and storage system which will be a massive undertaking as it involves many aspects I have yet to try my hand at. I’ll think about it while finishing up all this stuff.
Thanks for reading! I hope the pictures helped this time around. I’ll be back with more soon.