[SOLVED] Different Main Menu Background Upon Game Completion?

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
codenewbie
Newbie
Posts: 18
Joined: Tue Apr 17, 2018 11:21 pm

[SOLVED] Different Main Menu Background Upon Game Completion?

#1 Post by codenewbie »

Hello! I'm unfamiliar with both coding and Ren'Py. I would like to change the image background of the main menu once the player completes the game, but I don't know how to do that. I found some things through Google but I don't know where to put what.
Last edited by codenewbie on Thu Apr 19, 2018 2:36 pm, edited 1 time in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Different Main Menu Background Upon Game Completion?

#2 Post by Imperf3kt »

You need four simple things for this task.
The first is a default persistent variable which you can put anywhere outside a label (recommended suggestion is just before start label)
For example:

Code: Select all

default persistent.game_completed = False

label start:
The second requirement is to set that flag as True. This happens at the end of your game or any point you want, so it goes in the script file.

Code: Select all

    e "congratulations, you reached the good ending."
    $ persistent.game_completed = True
    return
The third step is to define a new background. This goes anywhere outside a label in the same way as we defined the persistent variable. Best place is gui.rpy

Code: Select all

define gui.game_clear_background = "path to file.png/jpg"
Finally, we need to check which background to show for the screen.

In screens.rpy, find the main menu screen (about halfway into the file)
Where it says add "gui.main_menu_background", we replace it with a conditional.

Code: Select all

    if persistent.game_completed:
        add "gui.game_clear_background"
    else:
        add "gui.main_menu_background"
Keep an eye on indentation. The number of spaces you put before each section of code is important.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Enchant00
Regular
Posts: 136
Joined: Tue Jan 12, 2016 1:17 am
Contact:

Re: Different Main Menu Background Upon Game Completion?

#3 Post by Enchant00 »

One way you can go about it is by using persistent data and conditional statements

So, in your script place this above your label start:

Code: Select all

default persistent.new_menu = False
Next, in your gui go to line #86 and change the gui.main_menu to like the one below

Code: Select all

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

## The images used for the main and game menus.
if persistent.new_menu:
    define gui.main_menu_background = "gui/main_menu_new.png" #change the one inside quotes with the filename of your new bg
else:
    define gui.main_menu_background = "gui/main_menu_new.png" #default main menu image
define gui.game_menu_background = "gui/game_menu.png"
Lastly, when you reach the end of your game just set this to true

Code: Select all

    $ persistent.new_menu = True
That's all :D Also, if you want to reset the bg back to its original menu, you'll have to click the clear persistent data in the renpy launcher. Try the above code then once it's good clear the persistent if you need to.

codenewbie
Newbie
Posts: 18
Joined: Tue Apr 17, 2018 11:21 pm

Re: Different Main Menu Background Upon Game Completion?

#4 Post by codenewbie »

I had to take the quotes out of the if statement that I added to screens.rpy, but it works now! Thank you both! :D

Post Reply

Who is online

Users browsing this forum: No registered users