[SOLVED] Any way to access store variables from CDS function?
Posted: Sat Apr 06, 2024 7:32 pm
Is there a way to access a variable that has been initialized with "default" or "define" inside a CDS (which itself required "python early")?
I'd like to have something like this (simplified example):
Afterwards, I'd like to use the object in some screens:
Whenever I try to access the variable from the CDS handler code, I get:
If I try with "store.my_complex_system_object" I get:
My understanding is that Ren'Py will run the "python early" block first, which means the variable hasn't been defined yet, but I need the complex object to be accessible to the rest of the game code. I could initialize the variable inside the "python early" block, but it's my understanding that doing this can cause issues with rollback and serialization (unless I'm mistaken?), so I'm wondering if this is even possible.
Maybe I could create a store itself programmatically instead? Not even sure that's possible, though...
Any help would be greatly appreciated.
I'd like to have something like this (simplified example):
Code: Select all
# File: 01_my_cds_parser.rpy
default my_complex_system_object = SomeComplexClass()
# define my_complex_system_object = SomeComplexClass() # Could also be "define"-d, honestly, it's going to be static state
python early:
def parse_my_cds(lexer):
# ...
def execute_my_cds(parsed_object):
my_complex_system_object.do_some_complex_stuff(parsed_object) # <-- Use the store variable here
def lint_my_cds(parsed_object):
# ...
renpy.register(
"my_cds",
parse=parse_my_cds,
execute_init=execute_my_cds, # I want to use my CDS to initialize some complex state
init_priority=10, # I thought using this would delay its execution until *after* the store was initialized, but no luck
lint=lint_my_cds
)
Code: Select all
# File: my_screen.rpy
screen my_screen:
if my_complex_system_object.flag:
...
else:
...
Code: Select all
NameError: name 'my_complex_system_object' is not defined
Code: Select all
AttributeError: 'StoreModule' object has no attribute 'my_complex_system_object'
Maybe I could create a store itself programmatically instead? Not even sure that's possible, though...
Any help would be greatly appreciated.