Using persistent data to swap main menu's background

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
Alem
Regular
Posts: 38
Joined: Wed Mar 15, 2017 7:53 am
Contact:

Using persistent data to swap main menu's background

#1 Post 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!

User avatar
chocoberrie
Veteran
Posts: 254
Joined: Wed Jun 19, 2013 10:34 pm
Projects: Marshmallow Days
Contact:

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

#2 Post by chocoberrie »


Alem
Regular
Posts: 38
Joined: Wed Mar 15, 2017 7:53 am
Contact:

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

#3 Post 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.

User avatar
vollschauer
Veteran
Posts: 231
Joined: Sun Oct 11, 2015 9:38 am
Github: vollschauer
Contact:

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

#4 Post 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 == . )

Alem
Regular
Posts: 38
Joined: Wed Mar 15, 2017 7:53 am
Contact:

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

#5 Post 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.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]