david wrote: > i just now learned what setter and getter is. > i did this to make my inventory function work properly. > i'll try to remove my getter.
The inventory list can be just for a in self.inventory: print a.name You can access object attributes from outside the object, they are public. > didn't know we had new-style classes. Yes, modern practice is to have your classes inherit from object, e.g. class Room(object): >>> def move(self,direction): >>> if self.location.exits.has_key(direction): >>> self.location = self.location.exits[direction] >>> print self.location.name >>> else: print 'alas, you cannot go that way' >>> def dig(self,direction): >>> lcoords = list(self.location.coords) >> >>Why do you convert to a list? You can access tuple elements by index. > > i need to change the coordinates of the current room to the room i'm > digging into so i can check world to see if that room exists. Yes, I understand the intent, but I think you can use self.location.coords everywhere you are now using lcoords - the conversion to list is not needed. >>but I think I would make ncoords a local variable and just say >> ncoords = (0, lcoords[1] + 1) >> >>With ncoords as a global you have a bug, you only set one element here, >>the other one will be left over from the last time through. > > i stuck that global up there to make something work. i forget what now. > maybe i should take notes or something :) i'm thinking i should write some > separate convert directions to coordinates function. That sounds like a good idea. But still you can create ncoords directly as shown above. Kent -- http://www.kentsjohnson.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor