Named store

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
User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Named store

#1 Post by SinnyROM »

I want to learn more about named stores in Ren'Py. Is it similar to the concept of namespaces in other programming languages? Can it be used in a way to organize global variables and functions?

For example, my game is composed of story/VN and RPG battle segments. Possibly the battle parts will have a lot of variables that pertain to it but not necessarily outside of battle. I could have turn orders, status ailments, battle formations, etc. in the global variables, but it might seem cluttered to have them around during the story segnents. What are the advantages and disadvantages in creating a named store for battle variables and functions for this example?

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: Named store

#2 Post by PyTom »

They're like namespaces in other programming languages.

The main downside is they're fairly incomplete - at this point, there's no way for a screen or a text substitution to access a named store except using its name.
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

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Named store

#3 Post by SinnyROM »

Great. I'm a little confused on what you mean by no way of accessing except by name though. This is what I have from the example documentation which shows the correct values without complaint - unless I'm thinking of something else entirely.

Code: Select all

screen debug():
    frame:
        has vbox
        text "variable: [variable]"
        text "mystore.variable: [mystore.variable]"

init python in mystore:
    variable = 0

init python:
    import store.mystore as mystore

label start:
    show screen debug
    $ variable = 1
    "Showing variables with a screen"
    "variable: [variable]"
    "mystore.variable: [mystore.variable]"
    

Post Reply

Who is online

Users browsing this forum: Google [Bot]