Go to Main Menu and auto reload script

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Go to Main Menu and auto reload script

#1 Post by Nero »

How can I return to main menu after clicking Main Menu option and after that have scrip auto reload the game? My game doesn't fully restarts once you go back to main menu which bugs game out.

So my idea would be to run this 2 functions one after another but the problem is that they cancel each other and can't be ran like that. Also I don't see a function in documentation that would force you back to main menu and then do Shift+R.

Seen requests for this in past but nothing helps. Any of you guys have idea how to implement this?

Also I want to call this function anywhere from the game and see it actually working like that, for example if you beat the game you still go back to main menu but game needs to be reloaded.

Code: Select all

    def reload_the_game():
        renpy.full_restart() # This will bring me back to main menu
        renpy.reload_script() # This will reload the game again

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Go to Main Menu and auto reload script

#2 Post by jeffster »

There are special labels which take control when you go to Main Menu:
https://renpy.org/doc/html/label.html#special-labels
Nero wrote: Wed Mar 06, 2024 6:16 pm How can I return to main menu after clicking Main Menu option and after that have scrip auto reload the game?
You click Main Menu option, and the control goes to those special labels (e.g. "before_main_menu").
There you can check if it's a "clean" start of Ren'Py, or coming back from the game "dirty".
In which case you can run whatever scripts you want.

However I would advise to correct your game script so that it would work without dirty hacks.
Maybe check how to use define, default, init etc. properly?

Post Reply

Who is online

Users browsing this forum: No registered users