Main Menu That Adds A New Imagebutton After Each Ending?

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
ShadowBoxGames
Newbie
Posts: 18
Joined: Fri Oct 07, 2016 9:58 pm
Tumblr: dozenroses.tumblr.com
Contact:

Main Menu That Adds A New Imagebutton After Each Ending?

#1 Post by ShadowBoxGames »

Hello, question about creating a changing menu here. I've searched for this topic all over the place and can't find any answers that perfectly match what I'm looking for.

I want to create a main menu where a new imagebutton is added after each ending. I understand how to use the $ persistent.ending == "" code to get the main menu screen to change, but I'm stuck on how I can make it so that the main menu screen itself stays the same, but a new imagebutton is added once you get a certain ending, and then how to make each one appear as you collect them.

Currently, all that is happening is one of the imagebuttons will appear after each ending, but I would like for them to add up as you collect each ending instead of replace each other. So instead of just showing the imagebutton for ending 1 after ending 1 is complete, and then switching to a different imagebutton for ending 2 once you play through again, I would like for both ending 1 and ending 2's imagebuttons to be present at the same time.

I'd appreciate any help, or if you can direct me to a thread that already deals with this! Also please, if possible, give detailed descriptions with coded visuals, because I am new to this and am learning as I go.

Here is the code for my main menu screen:

Code: Select all

screen main_menu():
    # This ensures that any other menu screen is replaced.
    tag menu
        
    imagemap:
        
        ground "menu/mainmenu_bg.png"
        idle "menu/mainmenu_idle.png"
        hover "menu/mainmenu_hover.png"
        
        hotspot (253,472,227,69) action Start() hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/StylishPiano.mp3"
        hotspot (274,552,221,71) action ShowMenu("load") hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
        hotspot (88,260,95,36) action ShowMenu("preferences") hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
        hotspot (248,230,75,39) action ShowMenu("about") hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
        hotspot (387,201,93,45) action Help() hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
    
    
    if persistent.ending == "Henry Good End": # This checks wether the variable for game completion is true or not. If yes, it will change the main menu.
        imagebutton auto "menu/henryendingkeychain_%s.png" xpos 1038 ypos 170 action ShowMenu("henry_gallery") hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
    elif persistent.ending == "Ned Good End":
        imagebutton auto "menu/nedendingkeychain_%s.png" xpos 1074 ypos 188 action ShowMenu("ned_gallery") hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
    elif persistent.ending == "Frank Good End":
        imagebutton auto "menu/frankendingkeychain_%s.png" xpos 959 ypos 188 action ShowMenu("frank_gallery") hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
    elif persistent.ending == "Joe Good End":
        imagebutton auto "menu/joeendingkeychain_%s.png" xpos 869 ypos 188 action ShowMenu("joe_gallery") hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
    elif persistent.ending == "":
        add "menu/blank.png"
And here is the code I have right now to make it appear (currently set it up in a menu format so I can quickly test it):

Code: Select all

label test_run:
    n norm "Here is a test to see if this is going to work. Choose the ending you want."
    
    menu pick_an_ending:
        x "What ending do I want?"
    
        "Frank's":
            $ persistent.ending = "Frank Good End"
            return
        "Ned's":
            $ persistent.ending = "Ned Good End"
            return
        "Joe's":
            $ persistent.ending = "Joe Good End"
            return
        "Henry's":
            $ persistent.ending = "Henry Good End"
            return   
The only idea I have of fixing this would be coding a bunch of endings with different combinations of the imagebuttons. Something like so:

Code: Select all

if persistent.ending == "Henry Good End" and "Ned Good End":
        imagebutton auto "menu/henryendingkeychain_%s.png" xpos 1038 ypos 170 action ShowMenu("henry_gallery") hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
        imagebutton auto "menu/nedendingkeychain_%s.png" xpos 1074 ypos 188 action ShowMenu("ned_gallery") hover_sound "Sounds/triangle.mp3" activate_sound "Sounds/da_ding.mp3"
But this is obviously a lot of work, and I am sure there must be a simpler way to do such...at least, I hope there is.
Last edited by ShadowBoxGames on Mon Jun 11, 2018 11:32 pm, edited 2 times in total.

User avatar
mitoky
Veteran
Posts: 316
Joined: Sat Feb 07, 2015 9:12 pm
Projects: The Purring Demon's Love, circus eterie
Contact:

Re: Main Menu That Adds A New Imagebutton After Each Ending?

#2 Post by mitoky »

If you use if & elif, it executes it in order. Hence if the first is "true" that one is shown and the others not. So use only "if" for each button and do it like this:

First of all we make a persistent for each ending:

Code: Select all

    
default persistent.ending_frank = False
default persistent.ending_ned = False
default persistent.ending_joe = False
default persistent.ending_henry = False
 
In game:

Code: Select all

label test_run:
    n norm "Here is a test to see if this is going to work. Choose the ending you want."
    
    menu pick_an_ending:
        x "What ending do I want?"
    
        "Frank's":
            $ persistent.ending_frank = True
            return
        "Ned's":
            $ persistent.ending_ned = True
            return
        "Joe's":
            $ persistent.ending_joe = True
            return
        "Henry's":
            $ persistent.ending_henry = True
            return  
and in the menu:

Code: Select all


    if persistent.ending_frank:
        ### Imagebutton Frank
        
    if persistent.ending_ned:
        ### Imagebutton Ned
        
    if persistent.ending_joe:
        ### Imagebutton Joe
        
    if persistent.ending_henry:
        ### Imagebutton Henry
        
    

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Main Menu That Adds A New Imagebutton After Each Ending?

#3 Post by Remix »

I would suggest, just make a persistent list of found endings, then iterate in the screen

Code: Select all

# a list we add each new ending to
default persistent.found_endings = []

label test_run:
    n norm "Here is a test to see if this is going to work. Choose the ending you want."
    
    menu pick_an_ending:
        x "What ending do I want?"
    
        "Frank's" if not "frank" in persistent.found_endings:
            $ persistent.found_endings.append( "frank" )
            return
        "Ned's":
             if not "ned" in persistent.found_endings:
                $ persistent.found_endings.append( "ned" )
            return

screen :

    hbox:
        text "Found\nEndings"
        for ending in persistent.found_endings:
            imagebutton:
                auto "menu/[ending]endingkeychain_%s.png" 
                action ShowMenu("[ending]_gallery") 
                hover_sound "Sounds/triangle.mp3" 
                activate_sound "Sounds/da_ding.mp3"
I think the [ending] interpolation should work fine (basically inserting 'frank' or 'ned' where needed.
Shout if it doesn't and myself or someone will advise a fix

Might need to adjust image names and galleries if you want 'ned_good' and 'ned_bad' for example
Frameworks & Scriptlets:

ShadowBoxGames
Newbie
Posts: 18
Joined: Fri Oct 07, 2016 9:58 pm
Tumblr: dozenroses.tumblr.com
Contact:

Re: Main Menu That Adds A New Imagebutton After Each Ending?

#4 Post by ShadowBoxGames »

mitoky wrote: Mon Jun 11, 2018 7:28 pm If you use if & elif, it executes it in order. Hence if the first is "true" that one is shown and the others not. So use only "if" for each button and do it like this:

First of all we make a persistent for each ending:

Code: Select all

    
default persistent.ending_frank = False
default persistent.ending_ned = False
default persistent.ending_joe = False
default persistent.ending_henry = False
 
In game:

Code: Select all

label test_run:
    n norm "Here is a test to see if this is going to work. Choose the ending you want."
    
    menu pick_an_ending:
        x "What ending do I want?"
    
        "Frank's":
            $ persistent.ending_frank = True
            return
        "Ned's":
            $ persistent.ending_ned = True
            return
        "Joe's":
            $ persistent.ending_joe = True
            return
        "Henry's":
            $ persistent.ending_henry = True
            return  
and in the menu:

Code: Select all


    if persistent.ending_frank:
        ### Imagebutton Frank
        
    if persistent.ending_ned:
        ### Imagebutton Ned
        
    if persistent.ending_joe:
        ### Imagebutton Joe
        
    if persistent.ending_henry:
        ### Imagebutton Henry
        
    
I did this, and it worked perfectly! Thank you for your help! I did not initially understand that aspect of the 'if' vs 'elif' statements, so that knowledge will be very useful in the future. :D

Post Reply

Who is online

Users browsing this forum: No registered users