Howto Run Game While Coding

Hi everyone I am wondering if I can setup the SDK to let me code and instantly see results in a running game. For example Notch who made Mindcraft is doing such a thing in this video: Is this possible with the JmonkeySDK? How can I create a similar setup, I think Notch speaks of debug mode, how can I set that up?

tl;dr: You need to click a button, it seems.

Long answer:
Some (many?) JVMs can exchange the code of a class inside a running program. Notch is using Eclipse, which will do it automatically; the SDK uses Netbeans, which requires that explicit click.
Note that this is limited. For example, OpenJDK refuses to replace methods that are being used, or resets to the start of the method which may have undesirable side effects. If you modify the layout of a class and an object of that class exists, this will fail, too. If you delete or rename a class that’s in use, this will fail (and I think sometimes it will fail even if the class is not in use).
I see Notch saving the game while doing the modifications. That helps because it tears down the game state, so a lot of code stops running and has a better chance of allowing an update.
I found that Hotswap works about 75% of the time for me :slight_smile:

If you’re interested in an approach to make everything replaceable, take a look at Erlang. Unfortunately, that’s a different programming language, so it won’t be of any use if you plan to stick with jME :stuck_out_tongue_winking_eye: (but it’s always good to know what’s Out There).

1 Like

Yeah, the apply changes button works well but only for certain changes. Anything too drastic (changing methods, etc) doesn’t get picked up. It’s still very useful for tweaking bits of behaviour though.

You can enable apply code changes on save by going into:

Tools -> Options -> Java -> Java Debugger - > “Apply code changes after save”

( Note that your project has to have Compile on Save enabled too, which is under your project properties -> Build -> Compiling - I believe this is on by default though )
And you still have to run in debug mode, but with that setup you will be “coding like notch”.


i didnt even realise this was possible… really useful, thanks!