[SOLVED] Different Main Menu Background Upon Game Completion?
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.
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.
-
- Newbie
- Posts: 18
- Joined: Tue Apr 17, 2018 11:21 pm
[SOLVED] Different Main Menu Background Upon Game Completion?
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.
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3792
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Different Main Menu Background Upon Game Completion?
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:
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.
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
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.
Keep an eye on indentation. The number of spaces you put before each section of code is important.
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:
Code: Select all
e "congratulations, you reached the good ending."
$ persistent.game_completed = True
return
Code: Select all
define gui.game_clear_background = "path to file.png/jpg"
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"
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
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Re: Different Main Menu Background Upon Game Completion?
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:
Next, in your gui go to line #86 and change the gui.main_menu to like the one below
Lastly, when you reach the end of your game just set this to true
That's all 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.
So, in your script place this above your label start:
Code: Select all
default persistent.new_menu = False
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"
Code: Select all
$ persistent.new_menu = True
-
- Newbie
- Posts: 18
- Joined: Tue Apr 17, 2018 11:21 pm
Re: Different Main Menu Background Upon Game Completion?
I had to take the quotes out of the if statement that I added to screens.rpy, but it works now! Thank you both!
Who is online
Users browsing this forum: No registered users