[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] dynamic pygame programming



The best situation for this would be to program things very
functional.  That way you can keep most of the program in an easily
reloadable module for when the game is paused.  So instead of:

class man:
   def update(self):
      if not self.touchground():
         fall
      if self.walking():
         move

You would have something more like this:

class man:
    def update(self):
        functions.manUpdate(self)

#in module functions
def manUpdate(self):
    ....

Then when you unpause the game:
reload(functions)


-----

Rebinding functions to existing instances is not pretty :)

Another more complex solution, one which I have not personally tried,
would be to make everything inherit from one level above where you
normally would inherit from.  That way you can reload the parent class
and all of the methods at least would be reloaded as well:

--superclasses.py--
class man:
   def update(self):
      if not self.touchground():
         fall
      if self.walking():
         move
--game.py--
import superclasses
class manInstance(superclasses.man):
    pass

Then I think when you reload superclasses, the methods on manInstance
will be delegated to the updated superclasses.man class.

I'm not so sure about that method.

-----
Also you could use exec to run all of your code.  But that is very bad
and insecure, and doesn't necessarily solve the problem of instances.

On Nov 7, 2007 9:46 AM, Casey Duncan <casey@xxxxxxxxxxx> wrote:
>
> On Nov 7, 2007, at 5:28 AM, Lionel Barret De Nazaris wrote:
>
> > Hi all,
> > I am considering using pygame for a new prototype and I wonder if
> > any of
> > you has any experience with what I call dynamic programming.
> >
> > Basically, I want to launch  Ipython,  import the main module of the
> > program, run it , then, pause it, modify any module and having them
> > reloaded and relinked.
> > All this without restarting the program.
> >
> > Would that be possible ? if so how ?
> >
> > It's very smalltalkish, but i wonder if it is possible in Python....
> >
> > Lionel
>
> Yes, absolutely yes. Just please don't ask me to debug it ;^)
>
> -Casey
>
>