Values returning 'None' for variables
Posted: Thu Apr 17, 2014 4:46 am
In my subclass for dict, the userid is being passed properly, but it is not properly setting self[userid] as its value is 'None' as well as the variable value. The variable spawnee is also returning 'None' for its value.
Code: Select all
def debug(msg=[]):
print('\n[D&D Debug] %s\n'%msg)
@Event
def player_spawn(game_event):
spawnee_userid = game_event.get_int('userid')
spawnee = dndPlayerDictionary[spawnee_userid]
debug(spawnee)
class _dndPlayerDictionary(dict):
def __missing__(self, userid):
value = self[userid] = dndPlayer(userid)
debug("%s %s %s"%(userid, self[userid], value))
return value
def __delitem__(self, userid):
if userid in self:
super(_dndPlayerDictionary, self).__delitem__(userid)
dndPlayerDictionary = _dndPlayerDictionary()
class dndPlayer(PlayerEntity):
def __new__(self, userid):
debug('New dndPlayer object')
# Since PlayerEntity requires an index for instantiation, we need to get the index
index = index_from_userid(userid)
self = super(dndPlayer, self).__init__(index)
# Call the "super" class (which is PlayerEntity in this instance) __init__ method with the index
return self
def __init__(self, userid):
PlayerDataDictionary[self.steamid].name = self.name
self.playerinfo = self.info