when does Ren’py think I’m in the main menu

n.b. This information is accurate to Ren’Py 7.3.x and should also work for versions 7.0.x, 7.1.x, and 7.2.x. It will most likely not work for versions prior to 7.

Screens are often the biggest programming component to a VN. There’s a ton of ground to cover there, but here’s a gotcha specific to the main menu that I thought I’d highlight first.

how the heck do I know if I’m in the main menu in the GUI?

Ren’Py’s engine always has a ‘store variable’ set for its main menu- that is, it keeps track of whether it’s displaying the main menu or not.

This allows you to display other screens differently if you have the main menu up. All you have to do is check the main_menu variable to see if it’s true or false. It can’t have any other value.

Example code:

        if main_menu:

            textbutton _("Start") action Start()

        else:

            textbutton _("History") action ShowMenu("history")

            textbutton _("Save") action ShowMenu("save")

This is code from within the base code’s navigation menu.

If you haven’t started or loaded a game yet, you’ll be in the main menu as the first screen. Ren’Py knows that you can’t look at your conversation history or save your game when no game is loaded yet. So instead it gives you a button to start a game.

So here’s a gotcha when designing a GUI- if you have elements that link back to the main menu, you can run into an error if you call action MainMenu().

Here’s an example:

textbutton _("Main Menu") action MainMenu()

This code is from a Preferences screen somebody coded. When they tried clicking on the text button, sometimes Ren’Py would crash.

The problem occurs when a game hasn’t been started or loaded yet. Ren’Py thinks it’s still in the Main Menu even when you bring up the Preferences screen. So it crashes when it tries to return to the Main Menu, because it thinks you’re already there.

When you’re in the Preferences screen before you’ve started a game, the Return() action will take you back to the Main Menu screen. To make sure the button executes the correct action, you can check the main_menu store variable.

if not main_menu:
     textbutton _("Main Menu") action MainMenu()
else:
     textbutton _("Main Menu") action Return()

tl;dr: Ren’Py considers you to be using the Main Menu screen until you’ve started or loaded a game.

The Main Menu screen has some other unique traits I’m curious to explore. Next up: playing videos in the Main Menu, and how other screens use the Main Menu.