How to write external 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
Message
Author
connorofford
Newbie
Posts: 2
Joined: Mon Dec 04, 2017 6:49 pm
Contact:

How to write external files?

#1 Post by connorofford »

Hello I'm a bit knew to python, i know mostly the basics and some of the advanced stuff but i'm stumped on how to create text.txt files in the game folder.
you know..
breaking the 4th wall and stuff
is there any way i can do that, if so please explain to me as if im a 3 year old cause i have no god damn clue :lol:

connorofford
Newbie
Posts: 2
Joined: Mon Dec 04, 2017 6:49 pm
Contact:

Re: How to write external files?

#2 Post by connorofford »

Dw i figured it out lol
$ f = open("filename.txt","w+")
$ f.write("text")
$ f.close()

puts file in game directory

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to write external files?

#3 Post by PyTom »

Note that this might not work on all platforms. It's actually a really hard problem, since the game's directory might not be writeable on all platforms. (It probably isn't on mac, iOS, and Android.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Apa
Regular
Posts: 103
Joined: Fri Dec 23, 2016 2:26 am
Location: NYC
Contact:

Re: How to write external files?

#4 Post by Apa »

PyTom wrote: Wed Dec 06, 2017 4:27 pm Note that this might not work on all platforms. It's actually a really hard problem, since the game's directory might not be writeable on all platforms. (It probably isn't on mac, iOS, and Android.)
Saves folder and its parent (where trace file is written) should be writable on platforms, right? :?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: How to write external files?

#5 Post by Imperf3kt »

On Android, apps have access to read and execute from folders, but they do not have permission to write.

Saving is done in another folder where it does have permission to write, perhaps you could work out how to use that folder?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Donmai
Eileen-Class Veteran
Posts: 1960
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: How to write external files?

#6 Post by Donmai »

Just a guess, but if connorofford question is related to the way DDLC plays with its internal files, I'm also intrigued and I believe what that game does is extract those .chr files from its .rpa archives. I don't know if that's the way it really works, but anyone interested may take a look here: https://www.renpy.org/doc/html/file_pyt ... ile-access
Don't know if that solves the problem of the game directory not being writable is some OS. I'm not even a programmer and I may be talking hf@ls#rh$jf& here. :)
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

trajano
Regular
Posts: 60
Joined: Sun Jun 16, 2019 7:59 pm
Github: trajano
Contact:

Re: How to write external files?

#7 Post by trajano »

@Imperf3kt where would we be able to write files in Android?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: How to write external files?

#8 Post by Imperf3kt »

I'm afraid this is something I never looked into so can't help with, sorry.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

trajano
Regular
Posts: 60
Joined: Sun Jun 16, 2019 7:59 pm
Github: trajano
Contact:

Re: How to write external files?

#9 Post by trajano »

Its okay, I found a workaround using io.BytesIO which provides me an in-memory file that I can manipulate as needed. So viewtopic.php?f=51&t=55866 works on Android as well.

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]