|
3.
|
|
|
All data reachable through fields on ``persistent`` is saved when Ren'Py terminates, or when :func:`renpy.save_persistent` is called. Persistent data is loaded when Ren'Py starts, and when Ren'Py detects that the persistent data has been updated on disk.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
../../source/persistent.rst:12
|
|
4.
|
|
|
The persistent object is special in that an access to an undefined field will have a None value, rather than causing an exception.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
../../source/persistent.rst:17
|
|
5.
|
|
|
An example use of persistent is the creation of an unlockable image gallery. This is done by storing a flag in persistent that determines if the gallery has been unlocked, as in ::
|
|
|
|
(no translation yet)
|
|
|
|
Located in
../../source/persistent.rst:20
|
|
6.
|
|
|
When the user gets an ending that causes the gallery to be unlocked, the flag must be set to True. ::
|
|
|
|
(no translation yet)
|
|
|
|
Located in
../../source/persistent.rst:33
|
|
7.
|
|
|
As persistent data is loaded before the init code is run, persistent data should only contain types that are native to python or Ren'Py. Alternatively, classes that are defined in ``python early`` blocks can be used, provided those classes can be pickled and implement equality.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
../../source/persistent.rst:38
|
|
8.
|
|
|
Merging Persistent Data
|
|
|
|
(no translation yet)
|
|
|
|
Located in
../../source/persistent.rst:44
|
|
9.
|
|
|
There are cases where Ren'Py has to merge persistent data from two sources. For example, Ren'Py may need to merge persistent data stored on a USB drive with persistent data from the local machine.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
../../source/persistent.rst:46
|
|
10.
|
|
|
Ren'Py does this merging on a field-by-field basis, taking the value of the field that was updated more recently. In some cases, this is not the desired behavior. In that case, the :func:`renpy.register_persistent` function can be used.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
../../source/persistent.rst:50
|
|
11.
|
|
|
For example, if we have a set of seen endings, we'd like to take the union of that set when merging data. ::
|
|
|
|
(no translation yet)
|
|
|
|
Located in
../../source/persistent.rst:55
|
|
12.
|
|
|
Persistent Functions
|
|
|
|
(no translation yet)
|
|
|
|
Located in
../../source/persistent.rst:69
|