The BUG that wasted 2 days...


So let talk about how my life got turned upside down for two days :/

It all started out with me starting up Game Maker 1.4 (I have 2.0 but I started writing the game in 1.4 and haven't seen a reason to switch over) and messing around with the menus and buttons. You'll see the updated version is a little more compact and the start screen is a little different. Then I ran the game and noticed all but 2 of my wall lights where showing no power. Odd... I checked the power (I had plenty). Then I noticed some of my switches are not powered either! I close, clean the build, restart. Now different lights and switches are on and other are out of power. HUH?! So I open all the objects I know that have code dealing with power, check and double check. Trace variables and the like. All seem fine. So the way objects check for power is every second or two they poll the nearest powered relay to see if it is active and if it is in range. Now I can't have all of them check it at the same time because that could cause stutters. So I give every object in the game a random seed value on creation that I use for different things (AI in companions for example). The electronic things only use this for randomizing the times they check for power.

I use a global variable that is being incremented by 1 every step (60 times a second) and then use that variable for the electronics to check to see if their time is up.

If((global.game_steps+random_seed)%120 == 0) {//check connection}

[I understand that modulus might actually be a slow operation here; give me another option if you think of one:)]

I could not for the life of me figure out why everything was broken now. Worrying that it was broken in a build I published I downloaded the previous build and checked. Everything was fine. So what had changed from the previous day? Game Maker 1.4 doesn't get updated anymore. It wasn't the second Tuesday of the month, so no Microsoft update. All I changed was the UI stuff in the menu. So off scouring that. Nothing references the global step variable (as I already knew; I was desperate). I knew it had to do with the step variable... it couldn't be anything else. I re-wrote the entire wall light, transformer, and relay code. Still was broken.

At this point I was broken too. The last backup I had was from like a month ago. That wasn't an option IMO. Then it dawned on me to try something I already tried at the beginning; but this time differently. I traced the game_step variable into a text file independent of the object it was being incremented from. I already tested to see if the variable was being updated, I mean I didn't touch any of that code of course it was [0,1,2,3]. it was incrementing perfectly in my debug window. The text file showed something weird though. The steps recorded in the text file where [0,3,6,9]. Huh? 

Notice the italic part in the previous paragraph. I had previously tested this variable in the same object it was being incremented in; the unique control object that got created at the beginning of the game. After tearing my hair out why I finally figured it out. My unique control object wasn't unique anymore... I had three of them. I check the menus rooms I was working in and found extra little control objects (that I must have added in by accident) way out in the margins of the rooms. If you've worked with 1.4's room editor you know what I am talking about. That was it. I deleted those little SOBs and everything was copacetic. Literally the first variable I had traced. It didn't show an error because each control object incremented steps by one and then printed it out. So I saw 0,1,2,3,4. I didn't see that it happened 3 times a step though. I even did a break in the debugger and it incremented fine every time. So if you had a step variable that was updating every by 3 every step and a random seed that when added never was equally divisible by 120 you'd never check to see if the connection was good or not.

So I am not sure what the moral of the story is... so choose one:

  • Trust your gut and try everything you can to test where you think the bug is before going on.
  • Make a separate debug object to trace your variables in to eliminate this error
  • Wish that Game Maker 1.4 had a [make this unique] check box
  • Write your own way to make an object unique {I have this now}
  • Switch over to Game Maker 2.0 because the room editor is probably a lot nicer to work with :)

Files

Sand - DEMO 153 MB
Version 102 Jul 03, 2020

Get Sand: A Superfluous Game

Buy Now$12.74 USD or more

Comments

Log in with itch.io to leave a comment.

Modulus on integer types should be pretty fast on modern CPUs, but not sure, does GameMaker use "double" or "float" for all numbers?

Oh man, I know how annoying bugs like this are. It can be so frustrating! Have you considered using version control like Git? It would really help your peace of mind if you know you can "go back in time" and see all the previous versions, and what you changed. I'm not sure if GameMaker's file formats make this hard or not. GitHub has free private repos now, so you can get your code up in the cloud for backup, without letting it out of the bag.

Sometimes the only way I've fixed a bug is to see the diffs of what I recently changed...

I use GIT on other projects, not sure how easy it would be to do for Game Maker... I'll have to look into it.