Sign in to follow this  
blueskies9041

Editing a Python Script during Runtime?

Recommended Posts

blueskies9041    138

So I was tasked at my college to embed Python into their framework - which provides all the necessary things to make a basic 2D game (sprites, window context, etc...).

 

So I successfully "embedded" Python 2.7 into their framework, and I can now call Python functions from C++ (using Visual Studio 2010, if that matters) and C++ Functions from Python. The python interpreter is setup properly, and I have decent Python debugging outputting to my console.

 

The last bit of the assignment says that they want me to figure out how to reload Python Scripts during application run-time, currently I can edit a script and see the changes if I close the app and open it up again (don't need to recompile).

 

How do I make C++/VS2010 detect the changes to my script during run time? 

 

 

Share this post


Link to post
Share on other sites
SimonForsman    7642

If you only need to reload scripts during runtime you could just toss in a button that reloads the script for you. (or opens a file dialog where you can select new scripts to load), or throw in a console where you can enter your own python code and have it execute immediatly.

 

If you need to detect when a file changes you can look here: http://stackoverflow.com/questions/931093/how-do-i-make-my-program-watch-for-file-modification-in-c

Share this post


Link to post
Share on other sites
blueskies9041    138

What does the C++ code for " Reloading " a  python script look like? I thought I had it figured out, in my games update loop I just re-assigned the PyObject * that was storing the handle to the script the same values ( handle contains the filepath of the script, and the name of the function im trying to call from it), I don't have to recompile to see the changes - I don't see why just opening the script & saving it isn't enough.

Share this post


Link to post
Share on other sites
SiCrane    11839

How did you load it in the first place? If you imported it as a module then you can reload it with PyImport_ReloadModule().

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this