How to have game create/search for/delete files?

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
Posts: 1
Joined: Sun Sep 16, 2018 3:23 pm

How to have game create/search for/delete files?

#1 Post by Myriadim » Sun Sep 16, 2018 4:30 pm

So I want to be able to have my visual novel create, search for, and delete files within the game folder, like how in Doki Doki Literature Club the game makes files when certain things happen and it only allows certain events to happen if a specific file does/doesn't exist in the game folder. How can I do this in my own visual novel? The kind of thing I want to happen is something along the lines of

if 'this file' exists then jump 'this label'

Is this something simple that I just missed, or is it a complicated task? Thanks!

User avatar
Hikari Beldrich
Posts: 14
Joined: Wed Dec 19, 2012 9:01 pm
Projects: Mystic Grimoire Series
Organization: Independent

Re: How to have game create/search for/delete files?

#2 Post by Hikari Beldrich » Sun Sep 16, 2018 9:31 pm

There are a few good examples of this in the Monika-After-Story/DDLCModTemplate Github here: ... h.rpy#L230

Use can use try/except/else blocks to when attempting verification against the files. I'm going to assume that the goal here is to identify the "presence" of a file only.

Here's a general block that should be able to handle that:

Code: Select all

        #Try reading the file to see if it exists (file is given as a path relative to the "game" directory):
        #The read failed, act on it here:
        #The the file exists, act on it here:
Some things to keep in mind though, is the goal to check the files as soon as the game is started? If yes, then you should be using "init python:" instead of "python" for these blocks. If you want something that can be checked at any point during a live run of the game then you might want to create a function that can run the check then call the function as a part of a "$ <your.python.statement>" call or a "python:" call.

You should also keep in mind how the game will recover the state of the files if the user does something you might not expect. Think about how the game could be self healing by regenerating the files in certain conditions or offer the player a "I just want to make it work again" nuclear option. The DDLC mod template I mentioned above handles this by checking a flag in an init python statement to offer the user a choice to delete their save files when resetting the game to a "pre-Monikapocolpyse" setting :p
Time moves ever onward. Ever, only, onward. -Hikari Beldrich
Finished Projects: "The Man and His Shell" ... 11&t=19006

Post Reply

Who is online

Users browsing this forum: No registered users