Roguelike MUD progress #4
Previous post: Roguelike MUD progress #3
Almost no progress on the game today. Instead, I was distracted by two different problems with my code reloading framework. Link to SVN revision.
- Use of slots:
class Tile(object):
This also seems to be an unsolved problem in the xreload module, which was written for normal Python namespaces.
__slots__ = [ "character", "fgColour", "bgColour", "flags" ]
TypeError: descriptor 'flags' for 'Tile' objects doesn't apply to 'Tile' object
I've not got any better ideas, and I am only using__slots__
for the sake of it. So the solution is to stop using them. - File-local instances of the classes it defines:
START_TILE = Tile("x", isMarker=True)
I've had to use a custom framework that has xreload-based code reloading, and encountered this same scenario there. In that case, it was because the class was registered with a external factory and subsequently used to churn out bad instances. These then hit the following error.
SPAWN_TILE = Tile("s", isMarker=True)
WALL_TILE = Tile("X", isPassable=False, isOpaque=True)
WALL1_TILE = Tile("1", isPassable=False, isOpaque=True)
WALL2_TILE = Tile("2", isPassable=False, isOpaque=True)
DOOR_TILE = Tile("D")
FLOOR_TILE = Tile(" ")
mapTilesByCharacter = {}
def IndexTiles():
for k, v in globals().iteritems():
if k.endswith("_TILE"):
mapTilesByCharacter[v.character] = v
IndexTiles()
CHAR_TILE_TEMPLATE = Tile("@", isPassable=False)
DRAGON_TILE = Tile("&", isPassable=False)
unbound method BLAH must be called with BLAH instance as first argument (got BLAH instead)
Solving that leaked class problem was simple, through locating the references to the throwaway new class, and substituting the old reference for them. Replacing instances though, is a little more complicated.
This error has gone away in 3.x I am told, which is a pity. As it serves as a good indication that there instances or class references have leaked outside of the code reloading system.
Next post: Roguelike MUD progress #5