Using Python for event scripting

Hi,

Suppose I code a game with Panda and Python, use py2exe for making the scripts into an executable but then also want to make use of Python for scripting ingame events. So out of my game (which is an exe now) I would like to have calls to (“un-exe-ified”) Python scripts.
How do I do that; or is there a better way?

Looking forward to your answers :wink:

I’ve been trying to do something like too. What I do is I have the scripts as txt (or py I do txt because I encrypt the file) files all in one folder then I use glob to get a list of all the file names in the directory. When I get the file names I open each file and write all of them to a single .py file in the applications directory. The .py file has a hardcoded name which is then imported when I run the my loading method. From there (as long as you’re scripts are classes) you should be able to call each script by creating new instances of the class. I can show you some code later if you still need it.

Hope this helps.

This is a possibility but it sounds a little…cumbersome if you understand what I mean. It certainly works, but is there not another solution?

Well, I haven’t tried anything like that, but if loading from a hard-coded module works, then instead of putting all the stuff from all the modules into one .py file by hand, you could probably just include * from all the modules into that one hard-coded module and that should do the trick.

However, I wonder why do that, anyway? I mean, making an exe out of your code is, for Python, pointless until you want to actually ship the game.

The only reason I see is modding. Is that the point?

You can use import to import custom modules by path. There are more advanced functions you can use in the imp Python module:
docs.python.org/library/imp.html