Archive for February, 2011

Double Trouble

I was up until 3.30 am last night (or should I say this morning) trying to work out why a certain section of code wasn’t working.

I had previously defined a set of enumerated constants, such that kWeak represented the value 0 and kStrong the value 1:

typedef ST {
   kWeak = 0,
   kStrong = 1
} StrengthType;

… and then checked an incoming variable against those constants in what is known as a ‘switch’ statement.

For those who don’t know, a ‘switch’ statement has a number of corresponding ‘case’ labels which tell the program where to jump to should the value contained in a particular variable equal that of a particular case label, and optionally a ‘default’ label should no match be found.

Here’s an example code snippet:

switch (strength) {
   case kWeak:
   case kStrong:
      NSLog(@"Unknown strength");

What was supposed to happen was that when the value of the strength variable was equal to the value represented by ‘kStrong’, i.e. 1, the program should jump to the ‘case kStrong:’ line and perform the instructions there. However, it would skip ALL the cases and jump to the ‘default:’ line, as if it couldn’t find a matching case value. But the debugger was telling me that the value in the ‘strength’ variable was indeed equal to that of ‘kStrong’, i.e. 1! What was going on?!

Well, after quite some time, having tried a number of things (including checking that there was a ‘{‘ (curly brace) immediately after the ‘switch (strength)’ statement, the omission of which can also cause a similar problem), I eventually discovered what was happening.

The file that this code was in was also including a header file which contained compiler constants used by another part of the program, including one like this one:

#define kStrong 7

When it came to the switch statement, then, the program was checking the ‘strength’ variable against a value of 7 rather than 1, and since there was no case statement with a value of 7, the ‘default:’ line was chosen.

So, the moral of the story? Be more careful with enumeration and compiler constant names and be aware that the compiler won’t complain if you use the same name in both situations.

P.S. The constant names and their definitions above have been simplified and made more explicit compared to those used in the actual Animal Tracker code in the hope that it would make the discussion easier to follow.


Read Full Post »

If you have been reading this blog for a while now, you may have noticed that I have yet to post any pictures of Animal Tracker or mention any specifics about the game. There are a couple of reasons for this.

Firstly, Animal Tracker began as a proof of concept and as such had place holder graphics just to allow me to get a feel for things. Some time later, I decided that the whole style and feel of the game needed changing, so I basically rewrote the whole game engine and created some more place holder graphics in the new style. And until I’ve developed all the main features of the game, I won’t know if I’ll need to change the way things are done again to allow some feature to be implemented. As a result, I’m hesitant in posting pictures of the game which may end up being somewhat different in the final version.

Secondly, the App Store is chock full of copycat games, some of which have been made by super speedy developers that have released their version even before the originals have been released! So, a bit like the Formula 1 teams who are currently testing their new cars as I type and who have had to shield their new chargers from the prying eyes of the competition until the testing stage, I’ve had to be guarded as to what sort of and how much information I post.

However, once the game is nearing completion, I’ll make up for the dearth of specific info and post lots of pictures and gameplay details.

Read Full Post »

Long time no see

It’s been a while since my last entry… November 22nd 2010 to be precise. Development has been ongoing since then, but at a somewhat slower pace than normal, mainly due to a rather chaotic Christmas period and a knock-on effect into January.

However, February is now here and work on Animal Tracker has finally begun again in earnest. These last few days I’ve managed to squash quite a few bugs that had been crawling about for far too long and I’ve refactored parts of the existing code base to make it more flexible. This has allowed me to add a couple of new features that weren’t easily achievable before.

As they say (whoever ‘they’ are), onwards and upwards…

Read Full Post »