Public writable directories on different platforms

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
srksrk 68
Newbie
Posts: 24
Joined: Fri Jul 19, 2019 8:10 pm
Contact:

Public writable directories on different platforms

#1 Post by srksrk 68 » Sat Feb 20, 2021 5:38 am

Hello,

so I am trying to create a file in a folder related to the game, and I am successful under Android and under Windows, and under some Linux installations. But I am having trouble under MacOS and some other Linux environments because config.gamedir seems to be write protected. Is there a general way to find a folder using Ren'py functions, methods, config or environment variables?

Under Windows, I have this:

Code: Select all

foldername = config.gamedir
Under Android, I can use this:

Code: Select all

if renpy.android and ("ANDROID_PUBLIC" in os.environ):
  foldername = os.environ["ANDROID_PUBLIC"] + "/game"
What can I use in the other cases?

Many thanks for your suggestions!

User avatar
zmook
Regular
Posts: 170
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Public writable directories on different platforms

#2 Post by zmook » Sat Feb 20, 2021 12:11 pm

There is a comment that says the Mac and Linux save directories are

Code: Select all

## Macintosh: $HOME/Library/RenPy/<config.save_directory>
## Linux: $HOME/.renpy/<config.save_directory>
It looks like this is defined in the internal function in `<YourGameName>.py`:

Code: Select all

# Given a directory holding a Ren'Py game, this is expected to return
# the path to a directory that will hold save files.

def path_to_saves(gamedir, save_directory=None):
I haven't tested that to confirm, but I would assume that if you use this function to define your writable directory, you won't have to worry about what OS you're on.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
zmook
Regular
Posts: 170
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Public writable directories on different platforms

#3 Post by zmook » Sat Feb 20, 2021 12:13 pm

In renpy/main.py, a config variable is defined for you:

Code: Select all

    # Find the save directory.
    if renpy.config.savedir is None:
        renpy.config.savedir = __main__.path_to_saves(renpy.config.gamedir)  # E1101 @UndefinedVariable
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

srksrk 68
Newbie
Posts: 24
Joined: Fri Jul 19, 2019 8:10 pm
Contact:

Re: Public writable directories on different platforms

#4 Post by srksrk 68 » Tue Feb 23, 2021 7:58 pm

Thanks, will try this out! But since I don't have a Mac, I cannot report back soon I fear...

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], skinnyfitgenes