[Resolved] How to remember screen navigation?

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
kei10
Newbie
Posts: 8
Joined: Fri Dec 02, 2016 6:46 am
Contact:

[Resolved] How to remember screen navigation?

#1 Post by kei10 »

Greetings, I'm Kei.
I'm fairly new here, and new to Ren'py.

Code: Select all

screen screen_chronicle():
    tag menu
    use game_menu(_("Chronicle"), scroll="viewport"):
        style_prefix "Chronicle"
        default screen_chronicle_index = "Player"
        default screen_player_inventory_index = 0
        fixed:
            frame:
                hbox:
                    null width 16
                    textbutton _("Player") action SetScreenVariable("screen_chronicle_index", "Player")
                    null width 16
                    textbutton _("Chronology") action SetScreenVariable("screen_chronicle_index", "Chronology")
                    null width 16
                    textbutton _("Item") action SetScreenVariable("screen_chronicle_index", "Item")
                    null width 16
                    textbutton _("Character") action SetScreenVariable("screen_chronicle_index", "Character")
                    null width 16
                    textbutton _("World") action SetScreenVariable("screen_chronicle_index", "World")
                    null width 16
                    textbutton _("Information") action SetScreenVariable("screen_chronicle_index", "Information")
I was trying to create a screen named Chronicle. It consists of a sub-menu of six textbuttons; Player, Chronology, Item, Character, World, and Information.
I want it to remember the navigation, for example; if I selected Character, exit the menu, then come back, it will stay in Character sub-menu.

But I have no idea how to do that. No matter what I tried, it just won't work. I'm slamming my head hard here.
If it works, one of those textbuttons should highlight as selected, but it didn't.

Edit: Additionally, I also want that kind of effect for the Game Menu when I press Escape. How do I achieve that as well?

Thanks, awaiting reply.
Last edited by kei10 on Fri Dec 02, 2016 6:04 pm, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How to remember screen navigation?

#2 Post by Ocelot »

I want it to remember the navigation
Use global variable for your screen_chronicle_index. Unlike screen variable it preserves its value between executions.
< < insert Rick Cook quote here > >

User avatar
kei10
Newbie
Posts: 8
Joined: Fri Dec 02, 2016 6:46 am
Contact:

Re: How to remember screen navigation?

#3 Post by kei10 »

Ocelot wrote:
I want it to remember the navigation
Use global variable for your screen_chronicle_index. Unlike screen variable it preserves its value between executions.
Where do I put that? How? ... Could you at least provide an example code?

Please?

Edit:
If I put "global screen_chronicle_index" in the screen code it says "global" is not a keyword.
If I put "global screen_chronicle_index" in the "init python:" line, it doesn't change anything.
If I set "default screen_chronicle_index = screen_chronicle_index", it doesn't work.
If I change "SetScreenVariable" to ""SetVariable", it doesn't work.
If I remove the "default screen_chronicle_index", it still doesn't work.

Seriously...

Edit2:
I am able to set the persistence of Game Menu by adding "SetVariable('_game_menu_screen', '<screen name>')" to each textbutton from "screens.rpy". But just not the one above...

Edit3:
From Edit2, it somehow only works for "quick menu", but not "game menu". I don't understand...
Last edited by kei10 on Fri Dec 02, 2016 9:49 am, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How to remember screen navigation?

#4 Post by Ocelot »

Code: Select all

default screen_chronicle_index = "Player"

screen screen_chronicle():
    frame:
        has hbox
        null width 16
        textbutton _("Player") action SetVariable("screen_chronicle_index", "Player")
        null width 16
        textbutton _("Chronology") action SetVariable("screen_chronicle_index", "Chronology")
        null width 16
        textbutton _("Item") action SetVariable("screen_chronicle_index", "Item")
        null width 16
        textbutton _("Character") action SetVariable("screen_chronicle_index", "Character")
        null width 16
        textbutton _("World") action SetVariable("screen_chronicle_index", "World")
        null width 16
        textbutton _("Information") action SetVariable("screen_chronicle_index", "Information")

label start:
    call screen screen_chronicle
    "After you make a selection and press return"
    call screen screen_chronicle
    "Selection is remembered"
    call screen screen_chronicle
    "And further calls to same screen works the way you want"
    return
< < insert Rick Cook quote here > >

User avatar
kei10
Newbie
Posts: 8
Joined: Fri Dec 02, 2016 6:46 am
Contact:

Re: How to remember screen navigation?

#5 Post by kei10 »

Thank you very much, @Ocelot.
It works perfectly.

Somehow, pressing ESC back to the game from game menu reverts back the _game_menu_screen variable...
Hmm...

Post Reply

Who is online

Users browsing this forum: Google [Bot]