Toggling persistent data from within the main menu screens?

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
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Toggling persistent data from within the main menu screens?

#1 Post by Imperf3kt »

I'm trying to switch an otherwise informative section of script, into a screen.
So far, I've managed to make a new screen and have it correctly display and scroll. I can add the text and have already ensured everything wraps nicely.

The issue I have though, is I have a persistent variable that affects some in-game menu choices.
I'd like to figure out how to make a button on the new menu, that allows me to toggle that persistent data.
Here is the relevant code:

script.rpy

Code: Select all

# Game start
label start:
    $ _game_menu_screen = None 
    $ renpy.block_rollback()
    
    scene black
    
    if persistent.prologue_finished:
        if persistent.lore_read:
            menu:
                "Read prologue?"
                "Yes":
                    jump prologue
                "No":
                    jump intro
        else:
            menu:
                "Read prologue?"
                "Yes":
                    jump prologue
                "No":
                    jump intro
                "Read Lore":
                    jump lore

    else:
        if persistent.lore_read:
            menu:
                "You have not read the prologue.\nIt is recommended you read it first, are you sure you wish to continue?"
                "Yes":
                    jump intro
                "No":
                    return
        else:
            menu:
                "You have not read the lore or prologue yet.\nIt is highly recommended you read them first, are you sure you wish to continue?"
                "Yes":
                    jump intro
                "No":
                    return
        
return
screens.rpy

Code: Select all

# Chapter Select Screen

screen chapter_select:

    tag menu
    use game_menu(_("Chapter Select"), scroll="viewport"):
        frame:
            imagebutton auto "css/pro_%s.png" xpos 0 ypos 0 focus_mask True action Start('prologue')
            imagebutton auto "css/lore_%s.png" xpos 0 ypos 101 focus_mask True action ShowMenu('lore_screen')

screen lore_screen:

    tag menu
    use game_menu(_("Lore"), scroll="viewport"):
        style_prefix "lore"

        vbox:

            text _("Text goes here {image=heart}") 

style lore_text is gui_text
New menu screen
New menu screen
In case it is of any use, I am using renpy 6.99.11.1749 and the new GUI, I would prefer an imagebutton if at all possible.

Additionally, the About screen, uses the following:
text _("Made with {a=https://www.renpy.org/}Ren'Py{/a} [renpy.version_only].\n\n[renpy.license!t]")
I cannot see how it displays the text it shows in place of the brackets, where does it pull that from? I cannot find it in any of the .rpy files, and this seems like a better solution that simply adding dozens of paragraphs of text "words, words, more words"

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: Toggling persistent data from within the main menu scree

#2 Post by PyTom »

I'm not quite sure what the first question is here. You can toggle a persistent variable using ToggleField(persistent, "fieldname").

For the second part, this is using the standard square-brackets based text interpolation, documented here:

https://www.renpy.org/doc/html/text.htm ... ating-data

This is using special Ren'Py-provided variables in the text namespace, but you can also use your own variable in the normal namepace, something like:

Code: Select all

define credits = """
A game by Imperf3kt.
"""
And then do:

Code: Select all

text _("[credits]\n\nMade with {a=https://www.renpy.org/}Ren'Py{/a} [renpy.version_only].\n\n[renpy.license!t]")

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
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Toggling persistent data from within the main menu scree

#3 Post by Imperf3kt »

Sorry about how I worded it, I was half asleep when I wrote it.
Essentially, my current script has $ persistent.lore_read in it at the end of the lore.rpy file

I wish to delete lore.rpy and instead turn it into a few paragraphs accessible from the main menu only, as seen in the prior screenshot.
Once a user has read the text, I somehow need to set the persistent variable to "True", so that upon accessing the actual game, the initial menu screens display different dialogue as per needed.

I've managed to do everything except set the persistent variable. I don't really want it to be automatic either, as a user may accidentally click "Lore" from the main menu, ignore it and click return, and then the game thinks the user has actually seen it when they haven't.

So to do this, I need to make some kind of interaction in a main menu screen, that sets this persistent variable, and reading through the documentation, I cannot see anything about it. The closest I can see is this: https://www.renpy.org/doc/html/persiste ... persistent
but it doesn't address what I'm after (or if it does, I cannot understand it)

I hope it makes more sense this time.

Thanks for answering the second question.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: Google [Bot]