We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm making a chrismas tree program, that when you hit esc a timer starts and a message appear on the screen before the game closes, but when I press the button the game automatically ends without the timer.
https://paste.ofcode.org/UqmfvSGJ6Z3DrVWaAhC2Av
I want to display stuff right before the game closes.
Answers
One cannot run your code as it is incomplete. Nevertheless, what you need is to override the exit() function as I show below. If you press ESC, hit the x button in your window or call exit(), the code will execute. The code that you want to execute when your program exits should be placed there. I used a for loop as a demonstration.
Kf
so I just create an exit function if I understand correct? and I wanted the stuff to happen before the program runs the exit. In my mind placing the exit in the timer should bought me a few seconds to show a message. Here the full page of the first script or whatever that first page is. https://paste.ofcode.org/adSM3bAURSHy2zwzRRYek9
This is one approach. Notice it is not 100% effective as it doesn't work if you close your window by clicking on the x in the top corner. But it works when you press ESC or any time you call the exit() function. I am deferring to call
super.exit()
only after the timer is done. Btw, do not use1/frameCount
as it doesn't do what you think it does. Below is the code.Kf
*******EDIT: Adding the while() inside the exit allows this code to work as you expected when you click on the X of the window of your sketch or when you press ALT+F4 in a Windows machine.