Typically you shouldn't have to explicitly delete variables, just let them 
leave scope and get garbage collected.

Sent from my iPhone

On Jul 12, 2010, at 11:25 AM, 音本四 <[email protected]> wrote:

> In my game that I'm working on, Senso (which is my first game in Pygame), 
> there is a main game class, Game, which handles things on the global level. 
> One thing it does is store each instance of game objects in dictionaries, 
> with the dictionary keys being each instance's memory address, grabbed with 
> id(). When an instance needs to be removed, part of the process involves 
> removing the dictionary reference of the instance, by calling "del 
> game.myclassdict[id(self)]" (replacing "myclassdict" with the actual name of 
> the correct dictionary). This seems to cause a problem: sometimes, this 
> action seems to reference a nonexistant key in the respective dictionary. 
> I've only experienced it with bullets. I've checked and double-checked the 
> code, and it doesn't seem that at any point I forget to add an instance to 
> the dictionary.
> 
> This problem has been around in my game for quite a while, but only recently 
> I have been able to consistently replicate it, while I was just messing 
> around with my game. Attached is my game as it is now. To see the error, run 
> senso.py and choose game 4 when prompted. It should happen pretty quickly (in 
> less than a second). Sometimes it takes longer.
> 
> Does anyone have any idea why this might happen?
> 
> (Also, please let me know if I'm doing something stupid! I won't feel bad! :) 
> )
> <Senso-.zip>

Reply via email to