How to program a choice that takes you back to the main menu?

Nothing Clever

Member
Game Developer
Mar 22, 2021
104
65
Hey friends!

So yeah, just began coding my game. There's a slightly 4th wall breaking scene at the start of the game where the main character essentially asks the player if they should continue on with the rest of the game. The player can either choose "No, you're a sicko!" or "Heck yeah, go for it!" The latter essentially continues the main plot, but I would like to make it so that the former shows a short scene of the character going "Wooh, you're right, that was a close call!" and then have it take the player back to the main menu. Slightly comedic. But uh, yeah, how would you go about doing that? :)
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,608
2,256
Python:
    menu:
        "Heck yeah, go for it!"
            pass

        "No, you're a sicko!"
            return

pass is RenPy for "do nothing". You use it when no action is really needed for a menu: choice, but the code structure (indenting) requires something. You could code a jump continue_onward instead (where "continue_onward" is a label somewhere else in the code), but it's more typing for the same result.

return (at least in this context) is "return to main menu". It's the last command any RenPy game should execute before ending. You could code a $ MainMenu(confirm=False), which is kinda the nuclear option.
 
Last edited:
Apr 24, 2020
192
257
return (at least in this context) is "return to main menu". It's the last command any RenPy game should execute before ending. You could code a $ MainMenu(confirm=False), which is kinda the nuclear option.
If the code is done correctly, then return should indeed take you back to the main menu. However, I foresee that any developer using that method will eventually trawl through their code, trying to figure out what it was supposed to return to and why it's returning to the main menu.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,969
16,222
$ renpy.full_restart() is another option.
It's even the most reliable option, mostly because it's designed especially for that.

The return one have an implicit condition, the "call stack" have to be totally empty. If it's not the case, then the player will in place be sent back somewhere in the game.
 

RanliLabz

Creating SpaceCorps XXX
Donor
Game Developer
Mar 5, 2018
2,402
6,310
It's even the most reliable option, mostly because it's designed especially for that.

The return one have an implicit condition, the "call stack" have to be totally empty. If it's not the case, then the player will in place be sent back somewhere in the game.
Really!? :eek: Eep - I use return all the time :LOL:
 

RanliLabz

Creating SpaceCorps XXX
Donor
Game Developer
Mar 5, 2018
2,402
6,310
Pray that your call stack will stay clean forever ;)
But you should really switch to renpy.full_restart(), you're starting to make more complicated code with the free roaming parts, and it's best to be sure.
Shall do! Lol - very glad I stumbled on this thread now... should save me a lot of problems down the line.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,608
2,256
Shall do! Lol - very glad I stumbled on this thread now... should save me a lot of problems down the line.

Realistically, most devs don't ever run into trouble - because they stick to using jump. I would mention the statement that gets people into trouble... but that's like telling a kid not to lick the frozen lamppost. It's not exactly cutting edge stuff - but you either know how to use it or you're not even aware it exists. There's always the exception, but in this case... I decided to stick with "ignorance is bliss".
 

Nothing Clever

Member
Game Developer
Mar 22, 2021
104
65
Hey y'all, just coming back to this thread after a few days. Just wanted to say that I'm still getting used to plugging in choices, so thank you for all of the great info. And yeah, I hope this thread helps other people out to. :)