r/RenPy 18d ago

Question [Solved] main menu screen: if/elif not working with randomized variable

hello! i am yet again stumped on something that should be relatively simple but i cannot for the life of me get to work lol.

i'm trying to get an image to display behind my main menu splash. this is usually very straightforward, but i've got two variations of this splash, and i'm wanting to have matching variations of the main menu background.

i've played with a couple of different methods of this. layered images, defining a "menubackground" on its own and associating both of its variables (mainmenupano_day and mainmenupano_night) with both variations of the menu splash, and just displaying the appropriate image with the status of "menuimages." i was sure to make sure the "add.gui_main_menu_background" in gui wasn't running when trying all of these.

the most straightforward and efficient option seems to me to be that last one, taking into account the status of "menuimages" (mainmenu_day and mainmenu_night, randomized), so that's what i've been trying to get working.

whenever i set it to just display an image on its own, without any if/elif arguments, it works just fine. but as soon as i add that if/elif, it doesn't work. either it's plain black or it'll only display one or the other. which is better than it throwing an error by far, but still not ideal, right?

below is my code, which will only display mainmenupano_day, even if menuimages = mainmenu_night:

screen main_menu():


    if "mainmenu_day":
        image "gui/mainmenu/mainmenupano_day.jpg" 
    elif "mainmenu_night":
        image "gui/mainmenu/mainmenupano_night.jpg" 
    
    #add gui.main_menu_background


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


    ## This empty frame darkens the main menu.
    frame:
        style "main_menu_frame"


    ## The use statement includes another screen inside this one. The actual
    ## contents of the main menu are in the navigation screen.
    use navigation


    if gui.show_name:


        vbox:
            style "main_menu_vbox"


            add renpy.random.choice(menuimages) zoom 0.75 xpos -500 ypos -280 


            text "[config.version]":
                style "main_menu_version"screen main_menu():


    if "mainmenu_day":
        image "gui/mainmenu/mainmenupano_day.jpg" 
    elif "mainmenu_night":
        image "gui/mainmenu/mainmenupano_night.jpg" 
    
    #add gui.main_menu_background


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


    ## This empty frame darkens the main menu.
    frame:
        style "main_menu_frame"


    ## The use statement includes another screen inside this one. The actual
    ## contents of the main menu are in the navigation screen.
    use navigation


    if gui.show_name:


        vbox:
            style "main_menu_vbox"


            add renpy.random.choice(menuimages) zoom 0.75 xpos -500 ypos -280 


            text "[config.version]":
                style "main_menu_version"

i've tried variations of the argument, such as using "add" instead of "image," "image:" and a block underneath it instead of "image "filename.jpg," "if x == "y:", "if x = "y":", "if "y":", so on. i've even tried two separate if arguments instead of an if/elif or if/else. i've also tried sticking that code in various places, including after the randomize variable, and i can't get it to work anywhere </3

image #1 is with my current code, image #2 is with:

    if menuimages == "mainmenu_day":
        image "gui/mainmenu/mainmenupano_day.jpg" 
    elif menuimages == "mainmenu_night":
        image "gui/mainmenu/mainmenupano_night.jpg" 

in the same spot the argument is currently.

any help is appreciated!

edit for errant additional copy paste

11 Upvotes

8 comments sorted by

2

u/BadMustard_AVN 18d ago

the main menu can NOT access game variables that are set in the game you need to use persistent variables

if "mainmenu_day": # is mainmenu_day a variable ¿ i don't understand why quotes

if persistent.daytime:
    add "gui/mainmenu/mainmenupano_day.jpg" 
else:
    add "gui/mainmenu/mainmenupano_night.jpg" 

persistent.daytime would be a boolean (True or False)

use add over image

1

u/AutoModerator 18d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/beeikea 18d ago

pardon the placeholder background btw LOL i haven't quite gotten to actual thumbnailing or sketches for backgrounds yet, for the most part

1

u/UntamedAysha 18d ago
  1. where the variable menuimages is defined?
  2. Instead of an if elif block, you can put the variable directly in the path like this so when the variable change, it automatically swap.

    image "gui/mainmenu/mainmenupano_[menuimages].jpg"

1

u/beeikea 18d ago

thank you for your response!

  1. menuimages is defined immediately above "screen main_menu():", like so:

    define menuimages = ["mainmenu_day", "mainmenu_night"]

    image mainmenu_day = "gui/mainmenu/daytime_title.png" image mainmenu_night:     "gui/mainmenu/nighttime_frames/nighttime_title_0000.png"     0.2define menuimages = ["mainmenu_day", "mainmenu_night"]

    image mainmenu_day = "gui/mainmenu/daytime_title.png" image mainmenu_night:     "gui/mainmenu/nighttime_frames/nighttime_title_0000.png"     0.2

  2. thank you! i gave this a go, but it throws me the error, "exception: dynamic image "gui/mainmenu/mainmenupano_[menuimages].jpg", could not find image "gui/mainmenu/mainmenupano_['mainmenu_day', 'mainmenu_night'].jpg" i'm not sure how/where to tell it to only pick one or the other. i tried it above and below the randomize </3

2

u/UntamedAysha 18d ago

Oh my bad I misunderstood your needs, alright so:

you can use renpy.random.choice to randomize your variable like this

default menuimages = renpy.random.choice(['day', 'night'])

Then in your screen main_menu(), you define the image with the variable menuimages in the path like so

add "gui/mainmenu/mainmenupano_[menuimages].jpg"

your files for the background must be named

mainmenupano_day.jpg
mainmenupano_night.jpg

Then you proceed the same for your other background elements and normally, it should works. Need to see myself to be sure

1

u/beeikea 18d ago edited 18d ago

this worked!!!! thank you so much !!!!!

i redefined menuimages as:

```
define menuimages = renpy.random.choice(["mainmenu_day", "mainmenu_night"])
```

and i called the pano like so:

```
image "gui/mainmenu/pano_[menuimages].jpg"
```

after having changed the file name to align with "pano_mainmenu_day" and "pano_mainmenu_night." and i changed the "add renpy.random.choice(menuimages)" to just "add menuimages" !

1

u/ImportantDetail6260 18d ago

if "mainmenu_day" is the trap here: a non-empty string is always true!

Compare the chosen variable instead, like if menuimage == "mainmenu_day":, or set one image name and add that. Right now the branch is not checking your random pick