introduce store in renpy

In Ren’Py, store is a module that contains the global state of the game. It includes any variables, functions, and classes that you define in the script outside of a function or method.

The store module provides a namespace where you can access and manipulate the global state of your game, making it an essential part of developing complex Ren’Py games.

Variables that you define directly in the script (not inside a function or method) are put into the store namespace. For example:

define p = Character('Protagonist')

This creates a p variable in the store namespace, which you can refer to later in the script as store.p or just p.

In the Python code, you can access store by importing it:

import renpy.store as store

# Now you can access your global state variables through the `store` module
store.p = Character('Protagonist')

Any changes you make to store variables will persist across different parts of your game. They are saved when the player saves the game, and restored when the game is loaded.

Note that variables defined inside a function or method don’t go into store - they are local to that function or method. If you want to change a store variable from inside a function, you can do so by referencing it through the store module.

猜你喜欢

转载自blog.csdn.net/m0_57236802/article/details/131995248