Found an alternate way to fix restarting the game

As you can tell in the tutorial, moving the 3 integers messed up the code. So it needed fine tuning to get it working again.
If you take a look at my example i can explain a, somewhat easier way of fixing this.


Instead of moving the 3 integers into < void startgame() >
Leave the integers where they are outside the start, and update, areas so they will always be declared. Next go down to your <keycode.return> and “I won” lines.
Before the < startgame(); > Set the integers back to their original variables.
min = 1;
max = 1000;
guess = 500;
Then finish it with < startgame(); > like in the example i show.

Hope this helps, im learning as i go too but i wanted to challenge myself to find the answer.
Please tell me if i made a mistake explaining my code.

2 Likes

Nice thinking! I figured I could add my small improvement here too :slight_smile:

I went a (small) step further and decided to plonk the reassigning portions of the code into a new method I called void ResetNumbers (); [see lines 47-51] to make things a little cleaner.

This means that instead of where you’ve reassigned the three variables within void StartGame ();, you now only need to call the ResetNumbers (); function[see line 30].

The value of this is that you can now more quickly reset the range of your program by merely calling the new function. Of course this does technically add an extra line of code… but were you to hypothetically keep working with this program, or something similar, we’d have this neat function we can deploy :slight_smile:

1 Like