Page 1 of 1

Using persistent data to swap main menu's background

Posted: Sun Jul 09, 2017 9:11 am
by Alem
Hi, not good with coding so I'm pretty sure that I'm digging in a wrong direction. The big idea is quite simple - mark unlocked endings then change main menu's background. Each of my endings has:

Code: Select all

$ persistent.ed1 = 1
With the number of the corresponding ending. Then I tried to figure out how to swap the bg, checked the manual but it looked different from my menu's layout so I went to the GUI section of the config and decided to improvise like this:

Code: Select all

## Main and Game Menus #########################################################

## The images used for the main and game menus.

if persistent.ed1==1 && persistent.ed2==1 && persistent.ed3==1:
    define gui.main_menu_background = "images/all.png"

elif persistent.ed1==1 && persistent.ed2==1:
    define gui.main_menu_background = "images/ed2ed1.png"

elif persistent.ed2==1 && persistent.ed3==1:
    define gui.main_menu_background = "images/ed1ed3.png"
    
elif persistent.ed2==1 && persistent.ed3==1:
    define gui.main_menu_background = "images/ed2ed3.png"

elif persistent.ed1==1:
    define gui.main_menu_background = "images/ed1.png"

elif persistent.ed2==1:
    define gui.main_menu_background = "images/ed2.png"
    
elif persistent.ed3==1:
    define gui.main_menu_background = "images/ed3.png"
    
else:
    define gui.main_menu_background = "gui/main_menu.png"
Plus, added this to option's init to mark variables for the comparision:

Code: Select all

    python:
     
        if not persistent.ed1:
            persistent.ed1 = 0
            
        if not persistent.ed2:
            persistent.ed2 = 0
            
        if not persistent.ed3:
            persistent.ed3 = 0

No matter what endings I get, the main menu still looks the same using the last, else option (the default one).

Is my persistent data not registering? Or maybe I'm trying to do this in an absolutely wrong way?

Thanks!

Re: Using persistent data to swap main menu's background

Posted: Sun Jul 09, 2017 11:15 am
by chocoberrie

Re: Using persistent data to swap main menu's background

Posted: Sun Jul 09, 2017 2:03 pm
by Alem
chocoberrie wrote:I found a few threads that might be useful! :)

viewtopic.php?f=8&t=31247
viewtopic.php?f=8&t=26117
viewtopic.php?f=8&t=31867&p=369053#p369053
Thanks for the tips, but I ended up with this approach - define backgrounds in the GUI part like this:

Code: Select all

## Main and Game Menus #########################################################

## The images used for the main and game menus.

define gui.main_menu_background_all = "images/all.png"
define gui.main_menu_background_ed2ed1 = "images/ed2ed1.png"
define gui.main_menu_background_ed1ed3 = "images/ed1ed3.png"   
define gui.main_menu_background_ed2ed3 = "images/ed2ed3.png"
define gui.main_menu_background_ed1 = "images/ed1.png"
define gui.main_menu_background_ed2 = "images/ed2.png" 
define gui.main_menu_background_ed3 = "images/ed3.png" 
define gui.main_menu_background = "gui/main_menu.png"
Then swap them from the screens like this:

Code: Select all

screen main_menu():

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

    style_prefix "main_menu"

    if persistent.ed1=="True" and persistent.ed2=="True" and persistent.ed3=="True":
        add gui.main_menu_background_all
    
    elif persistent.ed1=="True" and persistent.ed2=="True":
        add gui.main_menu_background_ed2ed1
    
    elif persistent.ed1=="True" and persistent.ed3=="True":
        add gui.main_menu_background_ed1ed3
        
    elif persistent.ed2=="True" and persistent.ed3=="True":
        add gui.main_menu_background_ed2ed3
        
    elif persistent.ed1=="True":
        add gui.main_menu_background_ed1
        
    elif persistent.ed2=="True":
        add gui.main_menu_background_ed2
        
    elif persistent.ed3=="True":
        add gui.main_menu_background_ed3
        
    else:
        add gui.main_menu_background
I dunno, all the different styles and forms, and tags are too complex for my level. "Fur ze dumbz" crutch like this is clean and clear in what it does.

Re: Using persistent data to swap main menu's background

Posted: Mon Jul 10, 2017 4:18 am
by vollschauer
you can also do this:

Code: Select all

    if persistent.ed1 and persistent.ed2 and persistent.ed3:
        add "images/all.png"
you can do a check persistent.ed1 == True, but look at this https://www.python.org/dev/peps/pep-0008/ (Don't compare boolean values to True or False using == . )

Re: Using persistent data to swap main menu's background

Posted: Mon Jul 10, 2017 2:47 pm
by Alem
vollschauer wrote:you can also do this:

Code: Select all

    if persistent.ed1 and persistent.ed2 and persistent.ed3:
        add "images/all.png"
you can do a check persistent.ed1 == True, but look at this https://www.python.org/dev/peps/pep-0008/ (Don't compare boolean values to True or False using == . )
Thanks, I'm pretty sure this may come in handy.