More refactoring progress.

The work to restore functionality to my game before it was split up continues. I solved the hyperspeed problem, and have avoided properly dealing with object management up to this point.

Like I mentioned before, Wing Pro is super helpful for refactoring. They’ve got a dedicated refactoring tool than is essentially a search and replace tool, except it tries to determine whether or not self.target in one class is the same as the self.target in the other, so it will not change it by default, but you can easily click and set a new one.

I will admit refactoring like this is a pretty boring process. It’s mostly just adding a module name before most variables, but then I start to wonder if that’s the best way to do it, if I should use local objects or not, whether I should create a class that stores all the names as an attribute, but then doesn’t a dictionary do the same thing?

The problem came from decision to split it up into modules. The old code would say something like: if self != player: target player else target allOtherCreatures sort of deal. The issue was that I’d use the actual names of the objects, since everything was created in the global namespace. When I split the project up, it was no longer to available through common means. So the way I solved was add an isPlayer attribute to the player, and added all creatures into a list, which each instance used to create a target list. If self was player, then it would take all the creatures from that list and add them to its own, otherwise the target list would be culled for the instances with isPlayer == True. I suppose that I’ll have to isMob and isItem eventually, but that’s too far into the future for now.

I’ve also been trying to clean up my many print functions used for debugging, because often times I’d just use print self.target and that’s it, but I’m trying my best to change it to something like print ‘This is the target:’, self.target . I also don’t use .format as much as I could simply because I don’t like typing up {0} all the time. Lazy, I know.

No new content though to speak of, maybe I’ll create a new WP tag, just to filter out the posts with content updates or not…