We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am working on a small simple maze game, and am completely stuck on a problem that is probably all too easily solved. The idea is that the game starts over when you click on the "try again" button. I have done some research and many people with the same question solved it by calling setup()
, or by creating a reset() function that has all the starting variables in it. I tried this, but it doesn't work. The button itself works fine, but I can't for the life of me figure out how to get the program to reset. Any ideas?
Answers
Hopefully, your program is keeping track of what's going on in lots of different variables. Your reset() function simply needs to reset those variables to the values they had when setup() ended. Then call your reset() function when your button is pressed.
It's easy to describe and understand, but we can't debug "it doesn't work" without seeing the code of your attempt.
That is exactly what I tried, but it simply doesn´t do anything. I would link you the code, but I don't have it anywhere online, and it is far too much to copy/paste into a comment. Everything else works, I tested it with a println where I called the reset() function, and that worked just fine. I think the problem might be related to the fact the "game over" screen witht he button doesn't use any of the variables that are being reset, and so it can't be reset by resetting those? In which case I would to find a way to basically re-run the entire program...
Make the following changes:
1) Do not assign any variables at the global level. If you are assigning variables at the global level, copy those assignments into setup(). Also add assignments for variables that start with the default value.
2) Add a call to reset() as the last thing in setup().
3) Move ALL variable assignments from setup() into reset().
4) Move back any assignments that start with "load" back into setup.
Example:
START:
AFTER 1:
AFTER 2:
AFTER 3:
AFTER 4:
I've got this online example which resets by calling createBalloons():
http://studio.processingtogether.com/sp/pad/export/ro.9V7R1wu55fOiN/latest
Thank you for your hlp, TfGuy44, but if I do that the game breaks. The character won't move, the walls become transparent. I guess there's no easy answer to this.