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!
How to have game create/search for/delete files?
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.
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.
- Hikari Beldrich
- Newbie
- Posts: 16
- Joined: Wed Dec 19, 2012 9:01 pm
- Projects: Mystic Grimoire Series
- Organization: Independent
- Contact:
Re: How to have game create/search for/delete files?
There are a few good examples of this in the Monika-After-Story/DDLCModTemplate Github here: https://github.com/Monika-After-Story/D ... 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:
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
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
python:
try:
#Try reading the file to see if it exists (file is given as a path relative to the "game" directory):
renpy.file("myfile.txt")
except:
#The read failed, act on it here:
do_thing_B()
else:
#The the file exists, act on it here:
do_thing_A()
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" http://lemmasoft.renai.us/forums/viewto ... 11&t=19006
Finished Projects: "The Man and His Shell" http://lemmasoft.renai.us/forums/viewto ... 11&t=19006
Who is online
Users browsing this forum: No registered users