Ren'Py [SOLVED] New menu for Chapter selection

grima_grima

Verified Developer
Game Developer
Nov 24, 2021
521
1,995
Hello All!

I am new to RenPy and I am trying to create a new menu item to show a list of thumbnails so the user can select which chapter they want to play:
1661856848722.png
Code:
Python:
screen navigation():

    vbox:
        style_prefix "navigation"

        xpos gui.navigation_xpos
        yalign 0.5

        spacing gui.navigation_spacing

        if main_menu:

            textbutton _("Start") action Start()
            textbutton _("Chapters") action ShowMenu("chapter_selection")

        else:
"chapter_selection" code:
Python:
screen chapter_selection():

    tag menu
    use chapters
    textbutton _("Return"):
        style "return_button"
        action Return()
"chapters" code:
Python:
screen chapters():
    $ chapter_index = 1
    frame:
        vpgrid:
            cols 3
            spacing 10
            draggable True mousewheel True
            allow_underfull True
            xsize 780
            ysize 540
            scrollbars "vertical"
            side_xalign 0.5

            for q in chapter_list:
                $ lb_image = im.Scale(q, 234, 187)
                imagebutton:
                    idle lb_image
                    hover lb_image
                    action [SetVariable("triggered_by", "chapter"), SetVariable("start_chapter", chapter_index), Jump("warning")]
                    selected False
                $ chapter_index = chapter_index + 1
My "chapter_list" will have a list of images with the Chapter covers (I'm adding duplicate images just to add more images, I only have 3 chapters so far):
Python:
default chapter_list = ["001/000000-01.webp", "002/000000-01.webp", "003/000000-01.webp","001/000000-01.webp", "002/000000-01.webp", "003/000000-01.webp", "001/000000-01.webp", "002/000000-01.webp", "003/000000-01.webp", "001/000000-01.webp", "002/000000-01.webp", "003/000000-01.webp"]
default chapter_index = 1
And this is what it shows:
1661857483960.png

So far, so good. When I click one of the first 3 chapters, these actions are executed:
Python:
action [SetVariable("triggered_by", "chapter"), SetVariable("start_chapter", chapter_index), Jump("warning")]
This is my "warning" code:
Python:
label start:
    $ triggered_by = "start"
    $ start_chapter = 1

label warning:
    scene black
    "{b}You must be at least 18 years old to play this game. If you are under 18 you should close the game immediately!{/b}"
    menu:
        "Do you confirm that you are 18 years or older?"
        "Yes: I am at least 18 years old" if True:
            pause (0.5)
        "No: Please close the game" if True:
            $ renpy.quit()

    if start_chapter == 1:
        jump chapter_001
    elif start_chapter == 2:
        jump chapter_002
    elif start_chapter == 3:
        jump chapter_003
So, when I click in one of the chapters, the selected chapter starts. However, when the chapter ends, the game automatically starts, as if I had clicked the "Start" menu option.

This is what I have in the end of each of my chapter labels:
Python:
    if triggered_by != "start":
        jump the_end

#######################################################################
# The end
#######################################################################
label the_end:
    return
So that is my problem, I don't want the game automatically starting after the chapter is played. Ideally, the game should go back to the chapter selection menu or to the main screen. Can anyone provide some insight, please? Thanks in advance!
 
Last edited:

grima_grima

Verified Developer
Game Developer
Nov 24, 2021
521
1,995
Have you tried
$ MainMenu(confirm=False)()
to force return to main menu?
I tried that at the end of the chapter, if the chapter was not triggered by the "Start" menu, and it did not work, still starts the game automatically:
Python:
    if triggered_by != "start":
        $ MainMenu(confirm=False)()
 

limniris1

New Member
Jul 22, 2022
6
5
When the game has restarted, can you go check the value of 'triggered_by'?
Press shift+d to open developer options and check in variable viewer.
 
  • Like
Reactions: grima_grima

grima_grima

Verified Developer
Game Developer
Nov 24, 2021
521
1,995
When the game has restarted, can you go check the value of 'triggered_by'?
Press shift+d to open developer options and check in variable viewer.
It shows:
Python:
triggered_by = "start"
And thanks for the "Shift+D" tip, it is really useful! ;)
 

crabsinthekitchen

Well-Known Member
Apr 28, 2020
1,565
9,079


Code:
screen chapters():
    vbox:
        textbutton _("Chapter 1") action Replay("chapter1")
        textbutton _("Chapter 2") action Replay("chapter2")


label chapter1:
    call warning

    "Chapter 1"
    if _in_replay:
        $ renpy.end_replay()
    jump chapter2

label chapter2:
    call warning

    "Chapter 2"
    if _in_replay:
        $ renpy.end_replay()
    return


label warning:
    if persistent.over18:
        return
    scene black
    "{b}You must be at least 18 years old to play this game. If you are under 18 you should close the game immediately!{/b}"
    menu:
        "Do you confirm that you are 18 years or older?"
        "Yes: I am at least 18 years old" if True:
            $ persistent.over18 = True
            pause (0.5)
        "No: Please close the game" if True:
            $ renpy.quit()
    return
 
  • Like
Reactions: grima_grima

grima_grima

Verified Developer
Game Developer
Nov 24, 2021
521
1,995


Code:
screen chapters():
    vbox:
        textbutton _("Chapter 1") action Replay("chapter1")
        textbutton _("Chapter 2") action Replay("chapter2")


label chapter1:
    call warning

    "Chapter 1"
    if _in_replay:
        $ renpy.end_replay()
    jump chapter2

label chapter2:
    call warning

    "Chapter 2"
    if _in_replay:
        $ renpy.end_replay()
    return


label warning:
    if persistent.over18:
        return
    scene black
    "{b}You must be at least 18 years old to play this game. If you are under 18 you should close the game immediately!{/b}"
    menu:
        "Do you confirm that you are 18 years or older?"
        "Yes: I am at least 18 years old" if True:
            $ persistent.over18 = True
            pause (0.5)
        "No: Please close the game" if True:
            $ renpy.quit()
    return
Thanks a lot for this! Now, the game behaves exactly how I needed. When I select a chapter and go through it, then it goes back to the chapter selection. Perfect solution! :D(y)