Multiple .rpy for organization?
Hello, what I am thinking and trying to do is set up .rpy files for each book / Subject so for example, I have active_species.rpy which as my human_book = Book(parent=gloss_enc, title=_('Human'), subject=_('Species'), locked=False)
Then goes into the about_humans etc.
I also made a locations.rpy with pretty much the same setup with like so:
python: location = Book(parent=gloss_enc, title=_('Earth'), subject=_('Planet'), locked=False)
With the about_earth, and about_mars with Mars being locked, and I have about_mars_2 and so on. In my script.rpy I made a menu to ask about questions I.E.:
"Ask about Mars" j "Sure thing" $ about_mars.locked = False
with another question like so: "Ask about more facts on Mars" if not about_mars.locked: j "Ah yes, the rest of Mars" $ about_mars_2.locked = False
When getting to the show screen enc_button part, I get a trackback saying $ about_mars.locked = True NameError: name 'about_mars' is not defined? Before I started trying to organize things, everything worked, which I might go back to. Even though, I would like to put different entries into their own .rpy file.
My gloss_enc is in init 1 python: while my label setup_glos with the information on species are in just python:
Any help would be appreciated.
If they're in python blocks, I'm assuming they're inside a label which is reached in-game because you want the entries associated with save data. See: https://renpy-encyclopaedia.readthedocs.io/en/latest/user_guide/02-scope/01-global-vs-local.html
If they're in python blocks and not inside a label then depending where you put them they won't get called at all. I'm not sure if they'd even be accessible or if it depends on the load order of the file they're in.
That makes sense. Maybe I am trying to call the about_mars in a python: that is not grabbing it since it isn't global?
So here is my location.rpy. ` python:
location = Book(parent=gloss_enc, title=_('Mars'), subject=_('Planet'), locked=True)
about_mars = EncEntry(
parent=location,
number=0,
name=_('Mars'),
text=enc_utils.text_block("""\
Testing"""),
locked=True,
)
about_mars_2 = EncEntry(
parent=location,
number=1,
name=_('Mars'),
text=(
"Test part 2"
),
locked=True,
)
`
While I have Earth on the 0_entry.rpy which, I want to move that also to location for organizing. `
Using Encyclopaedia.
screen enc_button(): frame: background Transform(Solid('#000'), alpha=0.5) xfill True padding (8, 8, 8, 8)
hbox:
spacing 16
imagebutton:
idle "images/codex/books.png"
hover "images/codex/books_hover.png"
action ShowMenu(gloss_enc.list_screen, enc=gloss_enc)
xalign 0.05
yalign 0.05
Shown as part of a callback when an entry is unlocked.
screen notify_entry_unlocked(): text _("New Entry Unlocked") xalign 0.98 yalign 0.02
timer 2.0 action Hide('notify_entry_unlocked')
init 1 python: gloss_enc = Encyclopaedia(name="Codex")
@gloss_enc.on("entry_unlocked")
def notify_entry_unlocked(source):
"""This function is called when an entry is unlocked."""
renpy.show_screen('notify_entry_unlocked')
GlossEntry = EncEntryTemplate(parent=gloss_enc, locked=True)
label setup_cdx: python:
Earth = Book(parent=gloss_enc, title=_('Earth'), subject=_('Planet'), locked=False)
about_earth = EncEntry(
parent=Earth,
number=0,
name=_('Earth'),
text=enc_utils.text_block("""\
We live here."""),
locked=False,
)
about_earth_2 = EncEntry(
parent=Earth,
number=1,
name=_('Earth'),
text=(
"A lot of people live here!"
),
locked=True,
)
`
So in the location.rpy do I add init infront of python: for it to be global / usable?