Button to delete all save games & persistent data

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
Another_Tom
Regular
Posts: 61
Joined: Mon Apr 24, 2023 9:06 am
Completed: Harold And The Witches
Projects: Steven On The Run
itch: dantom
Location: Germany
Contact:

Button to delete all save games & persistent data

#1 Post by Another_Tom »

Sometimes you want to play a game from the beginning as if you never played it before, and what do you do? You delete each savegame by hand, click dozens of times to confirm, then navigate through various folders to delete the persistent files, and by the time you're done, half an hour has passed.
How about a text/image button that does this automatically?
(I didn't write the code myself just gathered it, it's all here in the forum).

Use this function with caution, if you hit the button all saves are lost aswell as persistent data.
Here's the python function which can be called by an action from a menu screen.

Code: Select all

init python:
    def reset_data():
        ## deletes all persistent data use with caution
        for attr in dir(persistent):
            if not callable(attr) and not attr.startswith("_"):
                setattr(persistent, attr, None)

        ## deletes all save games use with caution!
        for slot in renpy.list_saved_games(fast=True):
            renpy.unlink_save(slot)
        ## a Ren'Py relaunch is nessesary
        renpy.quit(relaunch=True)
And here is a textbutton you can use.

Code: Select all

textbutton _("Delete Save Games And Persistent Data") action Confirm("Are you sure to delete all persistent data?\nThis also deletes ALL saved games and cannot be undone.\nNotice: The Game will restart!", Function(reset_data))
Happy cleaning :)

Post Reply

Who is online

Users browsing this forum: No registered users