Quote of the Day: “Just show Alex an incorrect equation and he’ll get out of cover to correct you” – Danh, joking about absurd paintball strategies.
Music of the Day: A mix again, but there were large chunks of Metallica and The Who, so we’ll go with that.
I forgot to mention yesterday that Alex and I have discovered how to use code regions, which allow code to be separated into labeled, minimize-able chunks. Here’s an example of what I mean:
That’s a 92-line long script (you can see it on the left). But I’ve organized it down into those 3 big chunks, which means I can minimize those that I’m not working on and maximize the others whenever I want to. It’s way easier than scrolling through the entire script up and down to find what I’m looking for. To give you a breakdown of what those 3 regions mean: “Variables” is where I have all of my..well… variables set up. It’s a big set of declarations. The “Unity Methods” is where all of the default methods that Unity gives you are, things like Start (which is called, you guessed it, when the script starts) and Update (which is called every frame to check things that change on the fly). And finally, “Shield Methods” is where all of my custom-written methods are for the shield powerup are stored. Most of the logic is in there, but there’s a lot in Update as well to track the timer. It’s clean and readable, 2 things that coding both needs to be and often is not when you’re actually in the midst of working.
I polished off the shield and super attack modularability (Google keeps angrily yelling at me that that’s not a word. I don’t care. It gets the point across. And I enjoy spiting Google) this morning, then moved onto the random powerup. Remember when I said that I specifically made new methods for each powerup rather than shove it all in OnTriggerEnter? Wait, now that I think of it I don’t think I ever mentioned that. OK rewind for a second. I made separate methods for powerup triggering rather than shoving all the code in OnTriggerEnter (which is called when two colliders touch). I did that specifically so hat when I got to the random powerup, I could just call those methods alone rather than re-writing all of the code in the random powerup script. it was a rare moment of forethought. And it did indeed pay off.
Instead of re-writing the big chunks of code for shield, health, and super attack, I was able to achieve the same effect with just one simple call. There were still bugs, as is to be expected, but for the most part it worked as intended. However, one of those bugs was a persistent little bugger (Ha, see what I did there?). And it affected multiple powerups too. Anything to do with a timer. Basically, when the player handled pickups, a powerup’s timer was on the player, so it could be modified in that one place by any powerup that the player got. But when you give each powerup it’s own individual timer for that specific instance of the powerup, you get problems when you pick up multiple of the. It’s a rare occurrence, but a very frustrating one. Basically, I wanted it to be additive. For example, if you have a shield with 3 seconds remaining, and you get another shield powerup, it should add on the full duration of that shield to your existing one, making your shield last for an additional 5 seconds. The problem is that those two timers are in different places, so making them standard across all powerups is tricky. normally I would make the timer static, which does pretty much exactly that. But because I’m dealing with a bunch of other variables and objects at the same time, it would require me to make more things static, many of which I want to be individualized rather than standardized.
So I kept screwing around with numbers and timers, and finally got it to work with the shield. Needless to say i was very happy and ready to copy that over to super attack. just one small problem: super attack is JUST different enough that my solution for shield wouldn’t work. So, after trying (and failing) for almost an hour to create a whole new solution for super attack, I decided to just finish off the other parts of the random powerup and come back to super attack later. Those other ones were pretty easy, just straight copy-paste from the existing script into the new one, and make sure everything was assigned correctly. That done, I was about ready to head for home. I am satisfied with my progress so far, it’s far more complicated than I anticipated but I think I’m moving through at a good pace.
If you’ve made it this far, congrats! I will try to post a video to show off exactly what I mean tomorrow (insert oohs and ahhhs here), but no promises. Until next time!