Page 1 of 1

Help with file system?

Posted: Tue Nov 21, 2017 1:04 pm
by tohtamish
Hello!

I need some help with simple problem - I need to create simple file, not regular save file, and create in specified locaion on HDD, for example in "my documents", (it will be some kind of saves for next episodes of game). Well... How to do it? =)

Re: Help with file system?

Posted: Tue Nov 21, 2017 1:42 pm
by RicharDann
If I understand the documentation correctly, Ren'Py can do this for you. You might want to see here:

https://www.renpy.org/doc/html/persiste ... ersistence

Re: Help with file system?

Posted: Wed Nov 22, 2017 5:36 am
by tohtamish
Thanks! On my way to learn it. (Before I read easy "patch" feature but is seems good only for 1 patch, I just want to make episodes of game and all I need is the external save fail where I simply put some vars)

Re: Help with file system?

Posted: Wed Nov 22, 2017 6:10 am
by trooper6
You should only need to use multi persistent data for that.

https://www.renpy.org/doc/html/persistent.html

Re: Help with file system?

Posted: Thu Nov 23, 2017 6:29 am
by tohtamish
But how about new versions of game? If 1st version of game has 1st episode and has multipersistent object and second version of whole game has both 1st and 2nd episodes and one multipersistent object that is "clean" - like no game was played - so does it rewrite all game directories (and "saves" with persistent file)? Yes it does, in my opinion, in this way, when new episodes of game appear together as one entire game.

Is it impossible in ren'py to work with file in any external directory?

(reading python doks - there some hards with relative paths and also must be imported library sys, os - even can't think how to do it in ren'py...)

Re: Help with file system?

Posted: Thu Nov 23, 2017 12:20 pm
by RicharDann
tohtamish wrote:
Thu Nov 23, 2017 6:29 am
Is it impossible in ren'py to work with file in any external directory?
It is possible using plain python code, you just need to put it in an init python block. A very quick example:

Code: Select all

default n = None #Just a placeholder variable

init python:
    import sys

    def create_external_file(name,ext):
        filename = "C:\\"+ name + "." + ext #We put the path Here. 
        fl = open(filename,'w') #Open the file in write mode
        fl.write("Hello world!") #Write something in it, I assume it will be a text file.
        fl.close() #Close the file

    def read_external_file(fl):
        filename = "C:\\"+ fl #Specify the path where the file should be read from.
        fl = open(filename, 'r') #Open the file in read mode
        return fl.read() #For this quick example, simply return the contents of the file

label start:

    "Let's create a new file."

    $ create_external_file("test","txt") #We call the create function here.

    "Let's read the file."

    $ n = read_external_file("test.txt") #We read the file here and store it's content in a variable.

    "[n]" #Hello World!
I tried this and it succesfully created an read the text file in my computer's C:\ drive, if you don't specify a path it will create it in the game folder (or in the Ren'Py SDK folder if you're running from a test project). You can probably read and modify any type of file you want using code like this just like you would do it with python.

Persistent functionality was suggested because it's ready to use, and can save you a lot of time and effort needed for creating this kind of system. But yes if you're going to include both episodes in a new version I guess you may need to overwrite persistent in case the player hasn't played standalone episode 1 first.

Re: Help with file system?

Posted: Sat Nov 25, 2017 2:06 pm
by tohtamish
Thank you, RicharDann! Can you explain me one moment about multipersistent - where they are saved and what happens to them if, for example, first version of game has 1st story episode and multipersistent saved by finishing by player and second version of game has 1st and 2nd episodes - and pure persisnet as no one played - will it overwrite played persitent on install? If installation means copying files and overwriting new ones if such exist.

Re: Help with file system?

Posted: Mon Nov 27, 2017 10:10 am
by RicharDann
tohtamish wrote:
Sat Nov 25, 2017 2:06 pm
Thank you, RicharDann! Can you explain me one moment about multipersistent - where they are saved and what happens to them if, for example, first version of game has 1st story episode and multipersistent saved by finishing by player and second version of game has 1st and 2nd episodes - and pure persisnet as no one played - will it overwrite played persitent on install? If installation means copying files and overwriting new ones if such exist.
Multipersistent is created when the players saves the game, in the same folder where the normal savefiles are created. It is saved in a file called 'persistent', without an extension. Each Ren'Py project creates it's own save files and it's own persistent file.

I'd need to triple check to be absolutely sure, but from what I experienced when I was testing this some time ago, if you play Episode 1 version 1, save persistent, and then in version 2 you play episode 2 directly, it will load the persistent file in Episode 1's save folder. But if you start episode 1 in version 2, it will overwrite the data from episode 1, wich might lead to problems when you continue episode 2. So I'm not sure yet if you can use it for this particular case, I'll try it again as soon as I have the time, but if you want you can create a couple of test projects and experiment yourself with it.

Re: Help with file system?

Posted: Thu Dec 07, 2017 1:46 pm
by tohtamish
thanks, man, I've found them in username/appdata/roaming folders. That's all what I needed to know. But let's change our talk to near subject:

viewtopic.php?f=51&t=45448&sid=8fd68660 ... efd3a8e099

But it's only for one patch... If I plan few chapters - can I do it just adding patch1(chapter2) rpy- files? So I need to create firstly eampty folders, set chapter# persistent vars to False in main scrypt and then when new chapters is ready - bring them as patch1-2-3-etc RPY files with audio-images folders? If I plan many patches - am I supposing correct? Firstly set all chapter persistent vars to false in main scprit and just bring new content in RPY files?