Page 1 of 1

Adding a new button to Main Menu upon Game Completion?

Posted: Thu Mar 21, 2013 3:14 am
by Goblin Maiden
Hi, everyone, I'm trying to add a button to the Main Menu that will lead to an Extras screen where I can share a few tracks, some background info, etc.

The game runs fine, everything is hunky dory. Except for one thing. No Extras button is showing up. I've tried playing through the game, and even then no Extras button appears.

I tried adding a persistent line to the ending, both before and after the credits that run at the end (but before the return code) but it apparently doesn't work. Here's the code I'm using:

In the Script file, this is the last line of the game, the persistent code, and then after that the credits start.

Code: Select all

    'But I\’\m going to try and find it.'
    $ persistent.ending = "Ending 1"    

init:
    ## I put my credits images on this page because I copy-paste this whole file into
    ## all of my games. This way, all I need to change are the images themselves, and
    ## the music I use for the credits. Everything else stays exactly the same.
This is what I have for the main menu and the changed main menu with the Extras text button added:

Code: Select all

screen main_menu:  
    # This ensures that any other menu screen is replaced.
    tag menu          
    
    if persistent.ending == "Ending 1":
        use main_menu_1
    else:
        use main_menu
    
    # The background of the main menu.
    window:
        style "mm_root"

    # The main menu buttons.
    frame:
        style_group "mm"
        xalign .98
        yalign .98

        has vbox

        textbutton _("Start Game") action Start()
        textbutton _("Load Game") action ShowMenu("load")
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Help") action Help()
        textbutton _("Quit") action Quit(confirm=False)

screen main_menu_1:
    tag menu
    
        # The background of the main menu.
    window:
        style "mm_root"

    # The main menu buttons.
    frame:
        style_group "mm"
        xalign .98
        yalign .98

        has vbox

        textbutton _("Start Game") action Start()
        textbutton _("Load Game") action ShowMenu("load")
        textbutton _("Extras") action ShowMenu("extras")
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Help") action Help()
        textbutton _("Quit") action Quit(confirm=False)          
        
init -2 python:

    # Make all the main menu buttons be the same size.
    style.mm_button.size_group = "mm"
And here's the code for the Extras screen in question, at least what I have for it so far:

Code: Select all

screen extras:
    
    tag menu

    window:
        style "bg university"

        textbutton _("Track 1. Thinking of You") action "thinking of you.mp3"
        textbutton _("Track 2. Light Thought var 2") action "light thought var 2.mp3"
        textbutton _("Track 3, Eternal Hope") action "eternal hope.mp3"
        textbutton _("Main Menu") action ShowMenu("main_menu")
        textbutton _("Quit") action Quit(confirm=False)  
        
    frame:
        style_group "mm"
        xalign .98
        yalign .98

        has vbox
        
init -2 python:

    # Make all the main menu buttons be the same size.
    style.mm_button.size_group = "mm"
Let me know if any more info's needed. Thanks so much in advance for any help you can give. :)

Re: Adding a new button to Main Menu upon Game Completion?

Posted: Thu Mar 21, 2013 3:49 am
by Juny

Code: Select all

screen main_menu: 
    # This ensures that any other menu screen is replaced.
    tag menu         
   
    # The background of the main menu.
    window:
        style "mm_root"

    # The main menu buttons.
    frame:
        style_group "mm"
        xalign .98
        yalign .98

        has vbox

        textbutton _("Start Game") action Start()
        textbutton _("Load Game") action ShowMenu("load")
        if persistent.ending == "Ending 1":
            textbutton _("Extras") action ShowMenu("extras")
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Help") action Help()
        textbutton _("Quit") action Quit(confirm=False)
If you define persistent.ending to something else in another ending, the code above won't work anymore: you might want a variable to check if you saw ANY ending (and use it to add the extra), and a different one to track WHICH.

If for whatever reason you need separate screens (untested but the logic is there):

Code: Select all

screen main_menu: 
    # This ensures that any other menu screen is replaced.
    tag menu         
   
    if persistent.ending == "Ending 1":
        use main_menu_1
    else:
        use main_menu_2
   
screen main_menu_2:
    # The background of the main menu.
    window:
        style "mm_root"

    # The main menu buttons.
    frame:
        style_group "mm"
        xalign .98
        yalign .98

        has vbox

        textbutton _("Start Game") action Start()
        textbutton _("Load Game") action ShowMenu("load")
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Help") action Help()
        textbutton _("Quit") action Quit(confirm=False)

screen main_menu_1:
   
    # The background of the main menu.
    window:
        style "mm_root"

    # The main menu buttons.
    frame:
        style_group "mm"
        xalign .98
        yalign .98

        has vbox

        textbutton _("Start Game") action Start()
        textbutton _("Load Game") action ShowMenu("load")
        textbutton _("Extras") action ShowMenu("extras")
        textbutton _("Preferences") action ShowMenu("preferences")
        textbutton _("Help") action Help()
        textbutton _("Quit") action Quit(confirm=False)         
       
init -2 python:

    # Make all the main menu buttons be the same size.
    style.mm_button.size_group = "mm"

Re: Adding a new button to Main Menu upon Game Completion?

Posted: Thu Mar 21, 2013 4:02 am
by Goblin Maiden
It worked! Thank you so much, Juny!