FileSave, FileLoad and Restart Game prompts

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
Gazza
Newbie
Posts: 24
Joined: Wed Sep 19, 2018 5:18 pm
Contact:

FileSave, FileLoad and Restart Game prompts

#1 Post by Gazza »

I'm stuck with two problems:

The first, is that i decided to put a single save slot, so i replaced

Code: Select all

textbutton _("Save") action ShowMenu('save')
###
textbutton _("Load") action ShowMenu("load")
to

Code: Select all

textbutton _("Save") action FileSave(1)
###
textbutton _("Load") action FileLoad(1)
It works, aside from the fact the button is constantly on a selected state

i know

Code: Select all

confirm = False
kinda solves it, but it deactivates the overwrite prompt, which it's something that i want to keep, and i hope there is a workaround




The second is that, i added a continue button and, in a similar fashion (viewtopic.php?f=51&t=48154), i wanted to show the restart prompt, but ONLY when a save file exist, which means i have to check if the save file exist, but i can't grasp how to actually write the code




Thank you in advance ;u;

User avatar
Ibitz
Regular
Posts: 63
Joined: Thu Jul 27, 2017 4:47 pm
Projects: Magical Disarray (WIP)
Organization: Ibitz Visual Novels
Deviantart: http://ibitz.deviant
itch: ibitz
Contact:

Re: FileSave, FileLoad and Restart Game prompts

#2 Post by Ibitz »

I'm not 100% sure of what you're asking, so I'll just post codes of things like game prompts and whatnot and see if that can help?

In terms of your save button constantly being activated, maybe an imagemap might help with that issue?
Here's what my menu has and it has a hover and idle and idle/hover selected so it's not always stuck.

Code: Select all

screen navigation:

   # The background of the game menu.
    window:
        style "gm_root"
    
   # The various buttons.
    imagemap:
        ground "Navigation_ground.png"
        idle "Navigation_idle.png"
        hover "Navigation_hover.png"
        selected_idle "Navigation_selected_idle.png"
        selected_hover "Navigation_selected_hover.png"
        
        hotspot (44,530,125,69) action Return() 
        hotspot (170,531,117,67) action ShowMenu("save") 
        hotspot (288,530,115,71) action ShowMenu("load") 
        hotspot (404,528,115,72) action ShowMenu("preferences") 
        hotspot (520,530,121,71) action MainMenu() 
        hotspot (642,530,115,71) action Quit() 
And, here's my Yes/No prompts. Hopefully this could help?

Code: Select all

# Yes/No Prompt
#
# Screen that asks the user a yes or no question.
# http://www.renpy.org/doc/html/screen_special.html#yesno-prompt

screen yesno_prompt:
    modal True # A modal screen prevents the user from interacting with displayables below it, except for the default keymap.
     # The background of the game menu.
    window:
        style "frame_ground"
    
   # The various buttons.
    imagemap:
        ground "screens/frame_ground.png"
        idle "screens/frame_idle.png"
        hover "screens/frame_hover.png"
        
        hotspot (210,340,183,51) action yes_action
        hotspot (420,341,183,47) action no_action
     
    if message == layout.ARE_YOU_SURE:
        add "yes1no_are_you_sure.png" xpos 0.25 ypos .1
    elif message == layout.DELETE_SAVE:
        add "Are you sure you want todelete this save file-min.png" xpos 0.33 ypos .3
    elif message == layout.OVERWRITE_SAVE:
        add "Are you sure you want to overwrite this save-min.png" xpos 0.33 ypos .3
    elif message == layout.LOADING:
        add "loading will overwrite unsaved progress-min.png" xpos 0.33 ypos .3
    elif message == layout.QUIT:
        add "Are you sure you want to quit-min.png" xpos 0.33 ypos .3
    elif message == layout.MAIN_MENU:
        add "Are you sure you want to return to the main menu-min.png" xpos 0.33 ypos .3
As for continue buttons being in the main menu, this should help you out:

Code: Select all

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

    # The background of the main menu.
    window:
        style "main_menu"
    
    imagemap:
        ground "main_menu"
        idle "gui/mm_idle.png"
        hover "gui/mm_hover.png"
        
        alpha False
        # This is so that everything transparent is invisible to the cursor. 
        
        if not persistent.beaten:
            hotspot (489,223,187,54) action Start()
        else:
            hotspot (489,223,187,54) action Start("real")
        hotspot (491,276,187,54) action ShowMenu("save game")
        hotspot (492,328,187,54) action ShowMenu("load")
        hotspot (491,380,187,54) action ShowMenu("preferences")
        hotspot (490,435,187,54) action ShowMenu("Extras")
        hotspot (493,487,187,54) action Quit(confirm=False)
        if persistent.beaten:
            hotspot (489,223,187,54) action Start("continue")
Hopefully this can help you out somewhat.
Image

Ibitz is a self-taught coder/artist who works alone on their games. All games I create are freeware. If you need any help with coding or creating your game, just let me know. I'd be more than happy to help.

strayerror
Regular
Posts: 159
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: FileSave, FileLoad and Restart Game prompts

#3 Post by strayerror »

You can prevent the selected state on your buttons by explicitly declaring it as False:

Code: Select all

        textbutton _('Load'):
            action FileLoad(1)
            selected False
        textbutton _('Save'):
            action FileSave(1)
            selected False
As for checking a save file exists, you can do that using FileLoadable, so to (for example) show a button only if the save file exists, you could do:

Code: Select all

        if FileLoadable(1):
            textbutton _('Continue') action FileLoad(1)

Gazza
Newbie
Posts: 24
Joined: Wed Sep 19, 2018 5:18 pm
Contact:

Re: FileSave, FileLoad and Restart Game prompts

#4 Post by Gazza »

strayerror wrote: Fri Dec 20, 2019 7:07 pm You can prevent the selected state on your buttons by explicitly declaring it as False:

Code: Select all

        textbutton _('Load'):
            action FileLoad(1)
            selected False
        textbutton _('Save'):
            action FileSave(1)
            selected False
As for checking a save file exists, you can do that using FileLoadable, so to (for example) show a button only if the save file exists, you could do:

Code: Select all

        if FileLoadable(1):
            textbutton _('Continue') action FileLoad(1)
YES!
They worked perfectly, thank you very much!

Post Reply

Who is online

Users browsing this forum: Google [Bot], Pandar, simple_human