Newb compiling question?

I was watching Notch’s lifestream for ludumdare and during it, on several occasions he seemed to edit his code live, and it appeared to change things in the game window without having to stop / recompile?

Is this possible/ if it is, is it only possible for certain types of modification/changes? adding/remove of a system.out.println and perhaps a modification to a if or for loop?

Or was my eyes lying to me and I just didn’t see it properly?(if not, how do you set that up?)

JRebel does that (from experience, buggy, I think there was an issue with anonymous classes? that was a few years ago), might be others

Yeah JRebel is a plugin for Eclipse. I will try it out and see if it fits my coding style as I think it might. Thanks for the heads up

Eclipse will do it as standard for some changes if you run from debug mode instead if just run.

JRebel is needed for class or method hotswaping. JVM however can hotswap method body by itself, with some restrictions and yes, debug mode is needed for this.

@OP
What you saw was Notch using the JVM with debug mode on. This allows him to edit method bodies in as soon as he hits Ctrl+S (to save the file) it compiles that method and updates it in memory during run-time. Your eyes do not lie :wink:

How? Started in debug mode and updated text within a JLabel (or changing the background color) and it’s not shown when ctrl+s.

Are there restrictions, do I need JRebel for such changes or have I missed something?

For the normal debugger to work the method needs to be executed after the change, so changing a JLabel text would have to happen in a code execution that happened after you saved the file. It doesn’t unwind every call since the application started.

e.g. If you set the label text to be the seconds since the application started, and called the method that changes the text in a loop in your code, changing the method to display some other text, the next call to that method would get the new string displayed.

I’m guessing what ever you saw change in the livestream was something executed by a method called in the main game loop.

Endolf

I am just trying to test this out

I am displaying some text on the screen
While in debug mode(I am pretty sure I am?) I tried changing the x/y coordinate of a


g.drawString("test",300,250);

Its obviously calling drawstring every frame, so I am confused?

and I have no luck, am I missing some setting or something special?

I run eclipse, and click the little debug icon in the top?

do you do that in a loop like I suggested?, or is that drawn once?

Its in a loop

I managed to get it to work by calling to compile a new debug(I close the new one)

and the “existing one” is updated. But it won’t update unless I run debug a second time

Is there like an auto-update or a setting I need to configure so it automatically pushes out the saved file?

switch to debug mode, run in debug mode F11 / the bug button

change something, save file CRTL+s, then change appears in game

thats how I do it.

I do exactly that, it only updates if I click the bug button a second time after saving(2 instances are now running, but even the old version shows the saved changes)

Edit: Found the solution

Under “Project”
make sure “Build Automatically” is turned on or else it wont work. Once I enabled that, it all works good now!