[SOLVED] How to restart the game?

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
User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

[SOLVED] How to restart the game?

#1 Post by Kinmoku »

Hi all,

I've implemented a "reset all game progress" button which seems to be working just fine. However, when I call the main menu afterwards, the game crashes. I believe this is because my menu has a persistent variable in it and, since I've just deleted them all, it comes up with an error.

If there is a way to restart the game, instead of calling the main menu, I believe this should sort the problem. Is this possible?

Here's my full code. The reset button is in preferences:

Code: Select all

            button:
                action Show("reset_popup")
                style "mainmenu_choice_button"
                text "Reset Game" style "mainmenu_choice"
... which calls this pop up:

Code: Select all

screen reset_popup:
    window:
        add "mainmenubg"

    hbox:
        add "images/popup.png" xanchor 0.0 yanchor 0 xpos 410 ypos 200

    vbox:
        yanchor 0
        xanchor 0.5
        ypos 350
        xalign 0.5
        xmaximum 1000
        ymaximum 350

        label ("This will reset the game and delete all your progress.\nDo you want to continue?"):
            text_style "yesno_label_text"
            xalign 0.5
            yalign 0.5
            
        hbox:
            style "menu"
            ypos 300
            spacing 70

            button:
                action Jump("resetprogress")
                style "menu_choice_button"
                text "Yes" style "menu_choice"
                
            button:
                action Return()
                style "menu_choice_button"
                text "No" style "menu_choice"

    key "game_menu" action Jump("resetprogress")
resetprogress label:

Code: Select all

label resetprogress:
     $ persistent._clear(progress=True)
     call screen main_menu
In main_menu, I have this which shows up the first time you complete an ending:

Code: Select all

if len(persistent.endings) == 1:
        add "whiteout"

        hbox:
            add "images/popup.png" xanchor 0 yanchor 0 xpos 410 ypos 200

        vbox:
            yanchor 0
            xanchor 0.5
            ypos 245
            xalign 0.5
            xmaximum 1000
            ymaximum 350

            label _("You have finished your first play-through of... etc etc"):
                text_style "yesno_label_text"
                xalign 0.5
                yalign 0.5
                
            hbox:
                style "menu"
                xalign 0.5
                ypos 100
                spacing 70

                button:
                    action [Return(), AddToSet(persistent.endings, 1)]
                    style "menu_choice_button"
                    text "Okay" style "menu_choice"
And, at the top of my script.rpy, is this:

Code: Select all

init -2 python:
    if persistent.endings == None:
        persistent.endings = []
Last edited by Kinmoku on Wed Sep 21, 2016 6:28 am, edited 1 time in total.

User avatar
papiersam
Veteran
Posts: 231
Joined: Fri Aug 12, 2016 2:24 pm
Completed: Gem Hunt Beta, 1/Probably, Animunch
Projects: The Panda Who Dreamed
Contact:

Re: How to restart the game?

#2 Post by papiersam »

Using

Code: Select all

init -2 python:
    if persistent.endings == None:
        persistent.endings = []
Really only works when the program is reloaded. Try:

Code: Select all

label resetprogress:
     $ persistent._clear(progress=True)
     $persistent.endings = []
     call screen main_menu
Although, it depends on how much persistent data needs to be reinitialised after the delete. If it's just the endings, the aforementioned should suffice. If there's still an error, then there's a bit more data that needs to be reinitialised.

Hope that helps.

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: How to restart the game?

#3 Post by Kinmoku »

r_sami wrote:Using

Code: Select all

init -2 python:
    if persistent.endings == None:
        persistent.endings = []
Really only works when the program is reloaded. Try:

Code: Select all

label resetprogress:
     $ persistent._clear(progress=True)
     $persistent.endings = []
     call screen main_menu
Although, it depends on how much persistent data needs to be reinitialised after the delete. If it's just the endings, the aforementioned should suffice. If there's still an error, then there's a bit more data that needs to be reinitialised.

Hope that helps.
Hey thank you, this makes it work :) However, I'm wondering ... Is it possible to reload the entire game from within the game?

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: How to restart the game?

#4 Post by philat »

I would experiment with renpy.full_restart and renpy.reload_script. Not sure if either is exactly what you're envisioning, but seems a decent place to start.

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: How to restart the game?

#5 Post by Kinmoku »

philat wrote:I would experiment with renpy.full_restart and renpy.reload_script. Not sure if either is exactly what you're envisioning, but seems a decent place to start.
Thanks Philat :) I'll give these a go.

Post Reply

Who is online

Users browsing this forum: Google [Bot], henne