Make the game create a txt file after player choice

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
troye_idk_idk
Newbie
Posts: 7
Joined: Fri Jun 16, 2017 11:55 pm
Contact:

Make the game create a txt file after player choice

#1 Post by troye_idk_idk »

So hi! ive recently played DDLC and i wondered. How do i make the game create files in the main directory?

I've tried to do that:

Code: Select all

$ f = open("filename.txt","w+")
$ f.write("text")
$ f.close()
(i got it from there)
But it doesnt work, no new file in the directory, no error message, nothing.
my code:

Code: Select all

menu:
        "1":
            $ reply = "1"
            jump end1
        "test":
            $ reply = "test"
            python:
                f = open("filename.txt","w+")
                f.write("text")
                f.close()
            jump end1
    
i've also tried to do it like that:

Code: Select all

menu:
        "1":
            $ reply = "1"
            jump end1
        "test":
            $ reply = "test"
            $ f = open("filename.txt","w+")
            $ f.write("text")
            $ f.close()
            jump end1
    
But it doesnt work either.


pls help, i have very little knowledge in python and renpy.

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Make the game create a txt file after player choice

#2 Post by RicharDann »

When you run the game from the Ren'Py Launcher, the textfile isn't saved in the proyect's directory, it is saved in the directory where the Ren'Py SDK is (where renpy.exe). When the you compile the game, the text file will be saved in the game's executable directory. That's if you don't specify a path (like "C:\\filename.txt"). And it won't work on all platforms, as PyTom says in that thread.
The most important step is always the next one.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Make the game create a txt file after player choice

#3 Post by Ocelot »

Why do you need that? Generally it is a very bad idea, as there would be numerous occasion when main directory would be read-only (Mobile OS, installaton of your game in Program Files, playing from removable drives). There are probably alternative ways you can accomplish what you want.
< < insert Rick Cook quote here > >

troye_idk_idk
Newbie
Posts: 7
Joined: Fri Jun 16, 2017 11:55 pm
Contact:

Re: Make the game create a txt file after player choice

#4 Post by troye_idk_idk »

RicharDann wrote: Thu Dec 14, 2017 9:54 am When you run the game from the Ren'Py Launcher, the textfile isn't saved in the proyect's directory, it is saved in the directory where the Ren'Py SDK is (where renpy.exe). When the you compile the game, the text file will be saved in the game's executable directory. That's if you don't specify a path (like "C:\\filename.txt"). And it won't work on all platforms, as PyTom says in that thread.
Oh god, thanks a lot!

troye_idk_idk
Newbie
Posts: 7
Joined: Fri Jun 16, 2017 11:55 pm
Contact:

Re: Make the game create a txt file after player choice

#5 Post by troye_idk_idk »

Ocelot wrote: Thu Dec 14, 2017 9:55 am Why do you need that? Generally it is a very bad idea, as there would be numerous occasion when main directory would be read-only (Mobile OS, installaton of your game in Program Files, playing from removable drives). There are probably alternative ways you can accomplish what you want.
I'm using it to "break the 4th wall", im making this game for my friends and they use windows so i think its gonna be okay.
Thanks for the info tho!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot]