I have to say, first off, that I'm loving working on this project, because I'm learning so much. Such is the case with pointers. I consider myself pretty inexperienced when it comes to using them, so I'm always learning something new. Ofcourse, my programs have to crash 20 times before I learn the lesson[lol]
Today, I was writing some of the code for the grand overworld map. I realized that I'm not going to have the town be a seperate map, but rather a sub-map within the larger map of the world. Anyway, I had to write a routine that would iterate through the tile array, find any uninitialized tile pointers, and initialize them to the generic grass tile. So, I wrote the following code:
for(int i = 0; i < height; i++)
for(int c = 0; c < width; c++)
if(tiles[c] == NULL)
tiles[c] = new Grass();
Pretty confident in myself, I went and compiled the program, and it compiled just fine(that's not entirely true, but besides the point). However, the program crashed over, and over, and over again.
Now, I always wondered when looking at C++ code, why do people bother to initialize a pointer to NULL. Surely the pointer must already be set to NULL by default! Oh, how naive I am.
Long story short, I learned this lesson the hard way, but eventually fixed the problem. Now I've learned the fairly obvious lesson, you actually have to initialize a pointer to NULL to compare it to NULL.
Anyway, I'm pretty anxious to get the player code working so I can walk around in the game world.