Welcome to my Programming Blog...

I am currently working on a couple of projects: An original game called "Implosion" which I am porting from Flash to the iPad, and a remake of Q*bert in Python (pygame), as part of the class I am teaching. Please feel free to use the "Labels" (at right) to follow a specific project or theme. If you are one of my Python students, I recommend that you check out the Python thread.

Monday, May 3, 2010

... but will anyone listen?

You know, when you are a teacher, you have to expect (and accept) that some of the things you tell your students are going to in one ear and out the other. Teachers know that we are going to have to repeat ourselves or find new ways to get the ideas we are trying to express to stick. Every year, I talk to my AP students about the difference between primitives and objects and the ideas of pointers.

You would think I'd be paying attention, myself.

I got bogged down in a puzzle this weekend - I had Chip objects that had a set of coordinates for their current position, and another set of coordinates for their destination. I'd start them off the same, but if they were ever different from each other, they would move a tiny little bit towards the destination, until they arrived there. Except when I changed the destination coordinates, they would just jump to the new location - they wouldn't glide; they'd teleport!

If you understand pointers, you can probably tell what my problem was - but it took me a couple of hours to puzzle it out (and find some other bugs along the way, but that's another story). Because I had set the myLoc and myDest variables to point to the same object, when I changed the coordinates of myDest, it changed the coordinates of myLoc, too. When I went back and changed my setter methods to make clean copies of the (x, y, z) coordinates that weren't the same object, suddenly things startes working right.

I wonder what else I was saying that I didn't listen to? I'll bet I need to do a better job documenting my code....

No comments:

Post a Comment