How to add a continue button on main menu?

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
oatnoodles
Regular
Posts: 71
Joined: Tue Aug 03, 2021 6:26 pm
Projects: Samuda Interval
Organization: Tomuwa Entertainment
Deviantart: oatnoodles
Github: oatnoodles
itch: oatnoodles
Discord: oatnoodles
Contact:

How to add a continue button on main menu?

#1 Post by oatnoodles »

Hello! My current main menu looks like this:

Image

Which is great when starting a new game. However, I want to make it so if there's a save file, the button will show "Continue" instead of "New game."

Here's the current code:

Code: Select all

screen main_menu_navigation():

    imagemap:
        ground 'gui/main_menu.png'
        hover 'gui/main_menu_hover.png'

        hotspot (78, 824, 837, 192) action Start()
        hotspot (1019, 770, 471, 153) action ShowMenu('load')
        hotspot (1525, 752, 222, 125) action ShowMenu('preferences')
        #hotspot (109,656,479,771) action ShowMenu('about')
        hotspot (1769, 748, 112, 102) action Quit(confirm=False)


## Main Menu screen ############################################################
##
## Used to display the main menu when Ren'Py starts.
##
## https://www.renpy.org/doc/html/screen_special.html#main-menu

screen main_menu():

    ## This ensures that any other menu screen is replaced.
    tag menu

    style_prefix "main_menu"

    add gui.main_menu_background

    ## This empty frame darkens the main menu.
    frame:
        pass

    ## The use statement includes another screen inside this one. The actual
    ## contents of the main menu are in the navigation screen.
    ##
    ## We will replace this with our own main menu navigation.

    # use navigation
    use main_menu_navigation

    add gui.main_menu_background

    ## This empty frame darkens the main menu.
    frame:
        style "main_menu_frame"

    ## The use statement includes another screen inside this one. The actual
    ## contents of the main menu are in the navigation screen.
    use main_menu_navigation

    if gui.show_name:

        vbox:
            style "main_menu_vbox"

            text "[config.name!t]":
                style "main_menu_title"

            text "[config.version]":
                style "main_menu_version"


style main_menu_frame is empty
style main_menu_vbox is vbox
style main_menu_text is gui_text
style main_menu_title is main_menu_text
style main_menu_version is main_menu_text

style main_menu_frame: #(132, 402, 409, 572)
    xsize 409
    yfill True

    #background "gui/overlay/main_menu.png"

style main_menu_vbox:
    xalign 0.0
    #xoffset -30
    xmaximum 1200
    yalign 0.0
    #yoffset -30

style main_menu_text:
    properties gui.text_properties("main_menu", accent=True)

style main_menu_title:
    properties gui.text_properties("title")

style main_menu_version:
    properties gui.text_properties("version")
Ren'py amateur looking to learn as much as possible! Please be patient with me.

User avatar
Andredron
Miko-Class Veteran
Posts: 700
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: How to add a continue button on main menu?

#2 Post by Andredron »

oatnoodles wrote: Tue Dec 06, 2022 7:29 pm Hello! My current main menu looks like this:

Image

Which is great when starting a new game. However, I want to make it so if there's a save file, the button will show "Continue" instead of "New game."

Here's the current code:

Code: Select all

screen main_menu_navigation():

    imagemap:
        ground 'gui/main_menu.png'
        hover 'gui/main_menu_hover.png'

        hotspot (78, 824, 837, 192) action Start()
        hotspot (1019, 770, 471, 153) action ShowMenu('load')
        hotspot (1525, 752, 222, 125) action ShowMenu('preferences')
        #hotspot (109,656,479,771) action ShowMenu('about')
        hotspot (1769, 748, 112, 102) action Quit(confirm=False)


## Main Menu screen ############################################################
##
## Used to display the main menu when Ren'Py starts.
##
## https://www.renpy.org/doc/html/screen_special.html#main-menu

screen main_menu():

    ## This ensures that any other menu screen is replaced.
    tag menu

    style_prefix "main_menu"

    add gui.main_menu_background

    ## This empty frame darkens the main menu.
    frame:
        pass

    ## The use statement includes another screen inside this one. The actual
    ## contents of the main menu are in the navigation screen.
    ##
    ## We will replace this with our own main menu navigation.

    # use navigation
    use main_menu_navigation

    add gui.main_menu_background

    ## This empty frame darkens the main menu.
    frame:
        style "main_menu_frame"

    ## The use statement includes another screen inside this one. The actual
    ## contents of the main menu are in the navigation screen.
    use main_menu_navigation

    if gui.show_name:

        vbox:
            style "main_menu_vbox"

            text "[config.name!t]":
                style "main_menu_title"

            text "[config.version]":
                style "main_menu_version"


style main_menu_frame is empty
style main_menu_vbox is vbox
style main_menu_text is gui_text
style main_menu_title is main_menu_text
style main_menu_version is main_menu_text

style main_menu_frame: #(132, 402, 409, 572)
    xsize 409
    yfill True

    #background "gui/overlay/main_menu.png"

style main_menu_vbox:
    xalign 0.0
    #xoffset -30
    xmaximum 1200
    yalign 0.0
    #yoffset -30

style main_menu_text:
    properties gui.text_properties("main_menu", accent=True)

style main_menu_title:
    properties gui.text_properties("title")

style main_menu_version:
    properties gui.text_properties("version")
viewtopic.php?p=549947#p549947

User avatar
oatnoodles
Regular
Posts: 71
Joined: Tue Aug 03, 2021 6:26 pm
Projects: Samuda Interval
Organization: Tomuwa Entertainment
Deviantart: oatnoodles
Github: oatnoodles
itch: oatnoodles
Discord: oatnoodles
Contact:

Re: How to add a continue button on main menu?

#3 Post by oatnoodles »

Andredron wrote: Tue Dec 06, 2022 8:17 pmviewtopic.php?p=549947#p549947
Hi! Thank you for the reply. Unfortunately, that's not what I was asking for. For more clarification, I want the "New game" button to be replaced with a "Continue" button when there is a save game to load, and it would load the most recent save file. Here's a comparison:

ImageImage
Ren'py amateur looking to learn as much as possible! Please be patient with me.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: How to add a continue button on main menu?

#4 Post by _ticlock_ »

oatnoodles wrote: Tue Dec 06, 2022 9:03 pm
Since you are using imagemap, you need ground and hover for both Start and Continue.

Code: Select all

screen main_menu_navigation():

    imagemap:
        if renpy.newest_slot():
            ground 'gui/main_menu_continue.png'
            hover 'gui/main_menu_continue_hover.png'
            hotspot (78, 824, 837, 192) action FileLoad(renpy.newest_slot(), slot=True)
        else:
            ground 'gui/main_menu.png'
            hover 'gui/main_menu_hover.png'
            hotspot (78, 824, 837, 192) action Start()
            
        hotspot (1019, 770, 471, 153) action ShowMenu('load')
        hotspot (1525, 752, 222, 125) action ShowMenu('preferences')
        #hotspot (109,656,479,771) action ShowMenu('about')
        hotspot (1769, 748, 112, 102) action Quit(confirm=False)

User avatar
oatnoodles
Regular
Posts: 71
Joined: Tue Aug 03, 2021 6:26 pm
Projects: Samuda Interval
Organization: Tomuwa Entertainment
Deviantart: oatnoodles
Github: oatnoodles
itch: oatnoodles
Discord: oatnoodles
Contact:

Re: How to add a continue button on main menu?

#5 Post by oatnoodles »

Thank you! I did add this in, but it shows "Continue" even if there is no save in the slot. How would I make it show only if the player does have a save file?
Ren'py amateur looking to learn as much as possible! Please be patient with me.

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: How to add a continue button on main menu?

#6 Post by rayminator »

maybe try this

Code: Select all

imagemap:
        if renpy.newest_slot():
            ground 'gui/main_menu_continue.png'
            hover 'gui/main_menu_continue_hover.png'
            hotspot (78, 824, 837, 192) action FileLoad(renpy.newest_slot(), slot=True)
        elif not renpy.newest_slot():
            ground 'gui/main_menu.png'
            hover 'gui/main_menu_hover.png'
            hotspot (78, 824, 837, 192) action Start()
or try this way

Code: Select all

imagemap:
        if renpy.newest_slot():
            ground 'gui/main_menu_continue.png'
            hover 'gui/main_menu_continue_hover.png'
            hotspot (78, 824, 837, 192) action FileLoad(renpy.newest_slot(), slot=True)

        if not renpy.newest_slot():
            ground 'gui/main_menu.png'
            hover 'gui/main_menu_hover.png'
            hotspot (78, 824, 837, 192) action Start()

User avatar
oatnoodles
Regular
Posts: 71
Joined: Tue Aug 03, 2021 6:26 pm
Projects: Samuda Interval
Organization: Tomuwa Entertainment
Deviantart: oatnoodles
Github: oatnoodles
itch: oatnoodles
Discord: oatnoodles
Contact:

Re: How to add a continue button on main menu?

#7 Post by oatnoodles »

I tried both, sadly it still displays continue only.
Ren'py amateur looking to learn as much as possible! Please be patient with me.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: How to add a continue button on main menu?

#8 Post by Imperf3kt »

Saw this thread a while ago. Meant to post this.

Code: Select all

    if recent_save:
        $ recent_save_page, recent_save_name = recent_save.split("-")
            textbutton _("Continue") action FileLoad(recent_save_name, confirm=True, page=recent_save_page)
Placing this in the navigation screen with the rest of the menu buttons will make a continue button appear and load the latest save game when clicked, should one exist.

You can of course, replace the textbutton with whatever you want, all you require is the action and the python lines
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

User avatar
m_from_space
Miko-Class Veteran
Posts: 939
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: How to add a continue button on main menu?

#9 Post by m_from_space »

oatnoodles wrote: Fri Feb 17, 2023 5:16 pm Thank you! I did add this in, but it shows "Continue" even if there is no save in the slot. How would I make it show only if the player does have a save file?
The reason is, that there are different kinds of save games:

- normal save slots are named "1-1", "1-2" and so on
- quick saves are named "quick-1", "quick-2" and so on
- auto saves are named "auto-1", "auto-2" and so on
- reload saves are named "_reload-1", "_reload-2" and so on

So the solution to this depends on the question if you want to continue latest auto saves, quick saves, or normal saves (reload saves are for developing, when you use the "autoreload" feature).

Code: Select all

imagemap:
    # only check for normal save games, which start with a digit
    $ newest = renpy.newest_slot(regexp='\d')

    # alternative 1: check for quick saves and normal saves
    # $ newest = renpy.newest_slot(regexp='quick|\d')

    # alternative 2: check for auto, quick and normal saves
    # $ newest = renpy.newest_slot(regexp='auto|quick|\d')

    if newest:
        ground 'gui/main_menu_continue.png'
        hover 'gui/main_menu_continue_hover.png'
        hotspot (78, 824, 837, 192) action FileLoad(newest, slot=True)
    else:
        ground 'gui/main_menu.png'
        hover 'gui/main_menu_hover.png'
        hotspot (78, 824, 837, 192) action Start()
EDIT:

I realized that FileLoad() will mark the button it refers to as "selected", when it detects the "newest" game. I don't like it, but you can change this behavior using an argument called "newest". It is a keyword argument inside the function, so better not use this variable name ourselves to stay out of confusion.

Code: Select all

$ newest_game = renpy.newest_slot(regexp='quick|\d')

if newest_game:
    # don't make the button stay selected all the time by setting "newest" to False
    textbutton _("Continue") action FileLoad(newest_game, newest=False, slot=True)

Post Reply

Who is online

Users browsing this forum: Google [Bot]