RAD loop?
Did anyone use any techniques (in Idle or whatever) to hack on parts of their game *while* it was running to get instant feedback? Or did everyone do more of a classic "edit, run, test, stop, repeat" loop?(log in to comment)
Comments
I'm assuming that if the module in question contains no state (i.e. no mutable variables) then reloading the module is trivial, just use the 'reload' command (whether you do so from a REPL, or from some other means within the program.) I think that would work, but I haven't actually tried it.
But if your module contains mutable state (e.g. class definitions with instance variables) then I don't think a simple 'reload' can suffice. What should one do about all the objects of the redefined class that currently exist? If you've just changed the logic within methods, then that's fine, but if you've changed the name or definition of the data members then presumably the old instances won't work with the new code. You'd have to find some way to re-create each instance, presumably by calling the new class constructor once for each existing instance. That sounds fiddly and error prone to achieve in the general case, and even if you did it, you'd be resetting so much state that perhaps it would be no better than restarting the program again.
So I'm interested in the idea but puzzled as to how useful it could actually be.
http://vimeo.com/36579366
There is a livecoding module (http://code.google.com/p/livecoding/) that does this by overriding the import mechanisms in python, but yeah, the tricky part is working out how to persist state between reloads.
It would be fiddly, but in theory you could create some framework for storing some of the state at a given time, and reverting to that after you have reloaded all your modules. Ideally you'd also store input so you can replay your last few seconds while tweaking the level, physics or graphics, like in the video.
Something I will probably try out before the next pyweek is a debug interface that would let you manipulate constants from the game, and maybe an in game console. It's really tedious to have to keep restarting your game just to get something like jumping right.
I've been interested in this ever since I watched this video There is a livecoding module (http://code.google.com/p/livecoding/) that does this by overriding the import mechanisms in python, but yeah, the tricky part is working out how to persist state between reloads.
It would be fiddly, but in theory you could create some framework for storing some of the state at a given time, and reverting to that after you have reloaded all your modules. Ideally you'd also store input so you can replay your last few seconds while tweaking the level, physics or graphics, like in the video.
Something I will probably try out before the next pyweek is a debug interface that would let you manipulate constants from the game, and maybe an in game console. It's really tedious to have to keep restarting your game just to get something like jumping right.
Lab Lab Bunny Lab I reload code snippets that generate the creatures every time they are written to. This was really useful for quickly tweaking the stock creatures.
In I recently red about the programming language Circa which is extra designed for livecoding. There state is handled specially and can be kept persistent although it isn't separated from the rest of the code.
Pickle does claim to enable saving data and then loading into a newer version of an object, so if, as you say reloading a module that is stateless is trivial, then if you designed your game such that it pickles all the state, reloads the module, and then unpickles the state into the new objects, you'd probably have the basics in place to iterate w/o restarting your game each time.
At the very least, it should be doable to have the code that creates the window etc separate and throw out/reload the rest of your game such that you don't have to pay that startup cost, and do it automatically on saving a source file so you don't have to pay the tax of manually starting your game. Could make the iteration loop pretty tight.
richard on 2012/05/15 05:35:
I've never had a REPL in a game. I have been know to have unit tests though :-)