Tuesday, October 6, 2020

The Fears of an Ambitious Indie Developer

Whoa, this blog hasn't been updated in months now! With that last blog post, you might've assumed I went insane due to fears of color association or something. Well, despite a certain infamous game's "gremlins" showing me how dumb this world can be with restrictions and morals (which kinda discourages me), I haven't disappeared...though I now have fears that if Magical Mary were to become popular, that people would scrutinize every line of my code and hate me for the slightest offense, though people should be more open to others in my opinion.

My recent (real) fears and frustrations with people aside, Magical Mary's development has definitely slowed down, and this blog post will explain my mind's ideas of plans that are way too massive to go through with...

Starting Small

Before I get to the main point of this blog post, let's talk about a nice improvement made recently: the music system rewrite. For basically all publicly-released versions of Magical Mary (World of Kirbycraft and Mary's Magical Adventure included), level music has been queued up using an ACS script, named...well, numbered 254. (That's a very bad habit; Don't use outdated numbered scripts, people!) This script would look up the corresponding filename in a LANGUAGE lump (which was used to bypass having to make a string array that would be in memory constantly), then would forcibly start playing that song for the current player.

The one problem with this script was, well...what would happen if the player started drowning, which temporarily takes over the music? Also, how would it handle temporarily switching to "Fight Trap" during forced battles, only to return to the level's music after it's over? Well, it's complicated. Just...take a look at the scripts responsible. At least I'm not afraid to show this mess of code:

The infamous game has spaghetti code? Well, my code is like tangled-wires by comparison!

Yeah, I warned you, the old code really was the worst way to write a "music system". It's hard to even tell what any of the code does at a glance! Anyways, as for those two scenarios I mentioned, this is what both did:

  • Drowning - The game sends a weird command to script 254, which somehow makes it store every player's current songs into an array awkwardly named "pn_254_temp". It then overwrites the music with the drowning song (#11), which plays until the player dies, exits the water, or grabs an air bubble (which isn't even in any of the levels), at which point it restores the song ID stored in that array.
  • Forced battles - Rather than storing the current song in that array (which is so confusingly-handled that I honestly forgot about it when I programmed the ACS script for this), I'd just overwrite the player's music with Fight Trap (#4) then restore the level music using one of the ACS script's arguments.

Notice how both of these don't sound like they're the "right way" to handle music-switching. I bet other games have multiple slots for music, so jingles and temporary music can take over then give back control more naturally. I thought of this recently and decided to throw out the old, flawed system and add in a new, much better system that's still compatible with existing "script 254" calls.

With the new music system, there's five music slots, each of increasing priority, which the game constantly checks for, intelligently switching which slot it plays music from. Here's all of them, from lowest to highest priority:

  1. Level music - As it's always playing throughout the level and doesn't need to be changed often, this is the lowest-priority slot. (Yes, no longer does the drowning music override this!)
  2. Temporary music - This slot is for things like forced battles.
  3. Jingles - Though secret areas just use GZDoom's built-in code for that jingle, the sound-playing part could be scripted in the future, allowing them to...pointlessly cut off and restart the music. (There'd definitely be an option to disable that!)

    This slot would also be used for extra lives if they were still in the game. If you're expecting the drowning jingle, that doesn't use this slot, as it's too important to be cut off by secret areas and the like...
  4. Drowning music - To prevent it from being restarted by jingles and lesser-important things, which would make the jingle fall out of sync with the five-second countdown, there's a fourth music slot designated entirely for the scary drowning music...and to think I was scared of Sonic's infamous jingle but yet I put something like it in my own game...
  5. Transformed music - Though there hasn't been music heard while transformed in any version of the game, there's still a fifth slot for if I ever want to add it in. It's higher-priority than drowning music, as well...unlike Sonic, you can't drown when transformed in my game.
Here's the entirety of the updated music system. Some of the code might be illogically-written, but hey, for someone who hasn't gone to any kind of programming class, surely this is decent, right?

The Conflicting Thoughts

With the music system rewritten from (mostly) scratch, you may wonder, what about the other scripts? I'll be more honest than a certain infamous developer and admit that my game's ACS code is built upon older versions of itself; If I added a new feature, it would get added to an existing script or would be intertwined with other unrelated code. Some of the scripts in the game even date back to early World of Kirbycraft versions, complete with weird/incorrect indentation! Compare these two pictures, and you'll see the "PlayWindSound" script still in v2.1 can be found all the way back in World of Kirbycraft v1.0!

Magical Mary 1 v2.1-dev