Thursday, December 22, 2011

Actually some progress: Or I how I stoped worrying about variable corruption and learned to love the global

Yeah I finally got a fire lit under me. This fire got me to open up this old project and fix some bugs. Was a simple bug but how I got to it was something new.

So python and my monstrous amount of comments wasn't helping me and I needed some variable output. I however did not want to comment out all my debug prints, I've been doing that at work stead and didn't want to continue the practice at home. Realizing that I had an option of making a method to do print  outs and just comment out the print there but would be cumbersome and possibly require some debugging itself and smart passing or something I heavily avoided in the past, global variables. Global variables must have bitten me hard at some point in the past but how I don't' remember the specifics. Effectively Global variables does what the box says, makes a variable global, this means you global i here and you change it there, the i will be the changed version later. This can easily lead to variables causing unexpected bugs as you made a temporary variable that shared the same name without realizing it.

With this in mind debug_print_variable came to mind and I slapped it down in front of every method in my level class. Checkign when things were added and when things were moved, all the fun stuff that leads to bugs. Within the first running I realized the problem. The bug of the player character hitting themselves was caused by them being initiated at the start area and then the reset function move the player to it's starting position which cuases the "attack" event to replace the move. Since the player was at the starting position I never noticed this. So good success for "bad" programing practices.

Next up I'll have to figure out what to do next with it. Maybe add a weapon upgrade to pick up.

4 comments: