[SOLVED]Creating a file at a certain moment of the story

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
User avatar
TsukiWorks
Regular
Posts: 27
Joined: Sat Jun 23, 2018 6:50 am
Projects: The Misunderstood
Deviantart: TsukiWorks
Contact:

[SOLVED]Creating a file at a certain moment of the story

#1 Post by TsukiWorks »

Hello! I tried creating a file with python at a specific moment of my story, but I can't get it to work.
I used the code in the image below.
I'm a beginner when it comes to coding, so I might've messed something up.
Thanks in advance!
Attachments
Code.png
Code.png (4.01 KiB) Viewed 481 times

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Creating a file at a certain moment of the story

#2 Post by Per K Grok »

TsukiWorks wrote: Fri Jul 27, 2018 12:39 pm Hello! I tried creating a file with python at a specific moment of my story, but I can't get it to work.
I used the code in the image below.
I'm a beginner when it comes to coding, so I might've messed something up.
Thanks in advance!
You need to go through three steps:
Open the file for writing,
write and
close the file.

try this

Code: Select all

    python:
        with open("noteSaveMe.txt", "w") as f:
            f.write(" Save me")
            f.close()
I think the file will end up in the renpy folder but I gave it a unique name if you need to search for it.

User avatar
TsukiWorks
Regular
Posts: 27
Joined: Sat Jun 23, 2018 6:50 am
Projects: The Misunderstood
Deviantart: TsukiWorks
Contact:

Re: Creating a file at a certain moment of the story

#3 Post by TsukiWorks »

Per K Grok wrote: Fri Jul 27, 2018 1:25 pm
TsukiWorks wrote: Fri Jul 27, 2018 12:39 pm Hello! I tried creating a file with python at a specific moment of my story, but I can't get it to work.
I used the code in the image below.
I'm a beginner when it comes to coding, so I might've messed something up.
Thanks in advance!
You need to go through three steps:
Open the file for writing,
write and
close the file.

try this

Code: Select all

    python:
        with open("noteSaveMe.txt", "w") as f:
            f.write(" Save me")
            f.close()
I think the file will end up in the renpy folder but I gave it a unique name if you need to search for it.
Thank you, I solved it!

Human Bolt Diary
Regular
Posts: 111
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: [SOLVED]Creating a file at a certain moment of the story

#4 Post by Human Bolt Diary »

You don't need f.close() at the end. The "with open" statement will close the file at the end of the block.

Code: Select all

python:
        with open("noteSaveMe.txt", "w") as f:
            f.write(" Save me")
Should work just fine.

Post Reply

Who is online

Users browsing this forum: Belgerum