How do you make the game scriptly delete files in renpy

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
Just A Game Dev
Newbie
Posts: 4
Joined: Mon Jan 01, 2018 3:23 pm
Projects: Achter gesloten deuren
Contact:

How do you make the game scriptly delete files in renpy

#1 Post by Just A Game Dev » Mon Jan 01, 2018 5:50 pm

I'm working on a renpy game which involves a lot of messing with one character's files (cause it has character files that I added)
And for a layer of mystery I want the character file of her to disappear everytime she's off screen and appear when she's on screen.
(Kind of like a mechanism from doki doki literature club) And I want other files to appear to add a layer of mystery.

User avatar
Aoi14
Newbie
Posts: 23
Joined: Sun Dec 24, 2017 3:24 pm
Projects: GuardianS X
Location: Somewhere over the Rainbow
Contact:

Re: How do you make the game scriptly delete files in renpy

#2 Post by Aoi14 » Mon Jan 01, 2018 8:27 pm

You'll need to script this in Python, using the os family of commands. Here's something you could try:

Code: Select all

# At the start of script.rpy, add this code:
init python:
    import os

# Then, when you wish to delete files etc., try this.
label start:
    python:
        os.remove('Desktop/MyFile.png')
        # Specify the file path as well
If you want higher level file operations, e.g. you want to remove an entire directory and all of its contents, try Python's shutil module instead.

Code: Select all

init python:
    import shutil

label start:
    python:
        shutil.rmtree('esktopDay'')
        # This would remove the Desktop directory if I ran it properly
For more information(sorry I'm unbelievably bad at explaining this), visit this link for the os module: https://docs.python.org/2/library/os.html#os.remove
And this for shutil: https://docs.python.org/2/library/shuti ... til.rmtree

Let me know how you get on! :D
Last edited by PyTom on Mon Jan 01, 2018 9:13 pm, edited 1 time in total.
Reason: Pig-latined code to protect copy and pasters.
Working on VNs. As usual :P

Just A Game Dev
Newbie
Posts: 4
Joined: Mon Jan 01, 2018 3:23 pm
Projects: Achter gesloten deuren
Contact:

#3 Post by Just A Game Dev » Mon Jan 01, 2018 8:51 pm

Thank you so much!

Just A Game Dev
Newbie
Posts: 4
Joined: Mon Jan 01, 2018 3:23 pm
Projects: Achter gesloten deuren
Contact:

#4 Post by Just A Game Dev » Mon Jan 01, 2018 8:58 pm

Though I still don't really understand how to code in adding them?

User avatar
Aoi14
Newbie
Posts: 23
Joined: Sun Dec 24, 2017 3:24 pm
Projects: GuardianS X
Location: Somewhere over the Rainbow
Contact:

Re: How do you make the game scriptly delete files in renpy

#5 Post by Aoi14 » Tue Jan 02, 2018 10:04 am

Ahh, sorry! Totally forgot that you needed to add files as well.
However, to help you, I'll need a little more info:
• Where do you plan on adding the files to?
• Are they premade files(i.e. you've made an image already and just want it to appear) or do you want script.rpy itself to write the files?

2nd bullet point in more depth-
I feel that adding in files may require more coding. If you wanted a file(such as an image or video) to appear in a certain folder, you'd need to go about it in a different way than what I'm used to, since you can't just write an image out of thin air. However, if you wanted a file like a text file to appear, you can use Python scripting to write it for you. Try this link out: http://www.pythonforbeginners.com/files ... -in-python

The most advanced, but most awesome thing to do would be to write a file in a programming language itself and then use the os command to run the code. But I'm honestly not sure what exactly you're looking for, so feel free to try things out or get back to me :D
Working on VNs. As usual :P

User avatar
Empish
Veteran
Posts: 221
Joined: Thu Jan 14, 2016 9:52 pm
Projects: Efemural Hearts, It Ends With Graduation
itch: empish
Contact:

Re: How do you make the game scriptly delete files in renpy

#6 Post by Empish » Tue Jan 02, 2018 10:07 am

File I/O is relatively slow compared to other operations, because it has to communicate with the drive. To delete and re-add a file in that situation seems both wasteful and unnecessary. If you want to "add an air of mystery" why don't you just archive your files in your game so that no one can look at them? (at least not casually). Or update persistent data to change whether the character's info is available in the codex or not depending on whether they're on screen or not?

User avatar
Ocelot
Miko-Class Veteran
Posts: 849
Joined: Tue Aug 23, 2016 10:35 am
Skype: miinipaa
Contact:

Re: How do you make the game scriptly delete files in renpy

#7 Post by Ocelot » Tue Jan 02, 2018 10:43 am

Or simply rename file to some other name with unknown extention. If you wish, you might even have empty file with same name, when needed, so it would not be obvious where file is going to.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: APD13