Nugget is a disgusting word, isn’t it? Why the hell do we apply it to food?
Two shorter updates this week, rather than one long one. This one is especially short, though, because over the last weekend I’ve been working on nothing but the trailer – which I think is good, but it’s awaiting feedback from some trusted friends before I post it publicly.
The process of working on the trailer has been really interesting, though. I uncovered a lot of bugs, which is partly why it took so long to make – for example, I found something that was more of a feature than a bug, but which was having unintended side-effects in the rest of my code. It was a tiny segment of code, hidden away at the bottom of an unrelated script, which was making it impossible to increase the kinetopede’s speed.
So how the hell did I miss this? Usually I’m pretty good at spotting this kind of thing. Interestingly, I don’t think the problem is anything to do with programming – it’s a combination of psychological factors which meant I never noticed the bug in the first place.
I never realized that the kinetopede’s speed was limited.
This is the big one. I couldn’t solve the bug because I was having trouble spotting that it was a bug. All of the changes I made to the speed were very incremental, and when I played the game, I looked very closely at the tiny steam-train chugging along and convinced myself that there was a measurable difference in speed.
This is confirmation bias at its finest – I made a small change, and because I expected to see that change having an effect, I convinced myself that the effect was there. I only noticed there was a problem when the gap between my perception and the reality became too great – I more than doubled the speed so I could whiz around and find interesting things for the trailer, yet it was still moving along at the same sedate pace! Only at this point did I even realize there was a problem.
I worded the comments badly.
The MaximumSpeed code is a CRUCIAL bit of code in terms of how the game feels and plays, but for some reason – back when I was still very much new to coding – I sandwiched it halfway down the player object and then wrapped it up inside an unrelated script.
But it wasn’t lost entirely. I’ve looked over that script many times, but my eyes just slipped right over this crucial bit of code at the bottom. And you know why? Because I worded the comments badly, and it had the psychological effect of making my brain turn off almost instantly.
Let’s look at that piece of code again.
See the word “just” there?
That word is a bastard. Every time I got to this bit of code, I’d read the comment, and some idiot part of my brain would think, “oh, it’s ‘just’ keeping the speed under control. That seems reasonable! Time to move onto the next thing.”
This ‘helpful’ comment managed to actually completely obfuscate the code’s actual purpose. What does “keeping the speed under control” mean, anyway? That could mean that it represents a distant theoretical limit, accounting for speed upgrades which I haven’t yet added to the game. I think that was what I assumed it meant, somewhere in my addled little head. But really the word “just” was stopping me thinking about it even to that extent.
3. I failed to ‘clean up’ what I thought was an abandoned variable.
When I first started coding, I determined the speed of an object by dividing a large number by the room_speed. This was because I misunderstood the nature of the room_speed function – I had assumed that it meant the game’s FPS, and my intention was to ensure the game played smoother even if it slipped under 60 FPS.
Unfortunately, room_speed didn’t work the way I thought it did (I now use the fps_real function to achieve the desired result). So I changed all the variables which used it, with the exception of one – which I assumed was a legacy variable, unused in the main program, but which I was too lazy to clean up. I’ll delete that later, I always thought when I noticed it, usually because I was busy thinking about a different problem.
Turns out, if I’d deleted that variable, the game would have crashed. It was still very much in use – and cleaning it up, as I should have done from the start, would have sent me down a rabbit-hole which would eventually lead to the culprit code.
Anyway, that’s a little snippet of the bug-fixing process. That bug, and many other less interesting ones, have now been laid to rest. Hopefully I’ll be able to post the trailer up here on Thursday! See you then!