[Pythonmac-SIG] Problems with embedding

Sean Hummel seanh@unforgettable.com
Mon, 28 Jun 1999 19:36:35 -0700


Okay so here is one I haven't seen on the list yet.

I have written a GAME which embeds python, using it to describe the game's
logic.  While all the sprites are handled with the SpriteWorld Library.

Now as the game worked in the past, all the callbacks made into the
"__main__" module, contained an entire state of the game.  However using
this was too slow, once the game got more complex.

As a result, I attempted to store the state info inside of the "__main__"
module, and the root level, as just some variables:

import gameworld
import sprites

spritelist=[]

def    initializeGame(gw):
    ...
    newsprite=sprites.CreateFromCicnResource()
    spritelist.append(newsprite)
    return

def    idle(gw):
    print spritelist[0]
    return

When the "idle" function callback is made from the mainloop of the
application framework, the "spritelist" is still set to [], even though it
was added in the "initializeGame"


Is there something I'm not doing?  Is the context different in this case?
I've checked the obvious, like making sure that code for this module is not
getting released prematurely.