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.
What I want to do is, show different main menu background randomly (one of three pictures) everytime when entering the main menu.
I tried in gui.rpy like this:
## Main and Game Menus #########################################################
## The images used for the main and game menus.
$bgr = random.randint(0, 2)
if bgr == 0:
define gui.main_menu_background = "gui/main_menu_O.png"
jump origin
if bgr == 1:
define gui.main_menu_background = "gui/main_menu_R.png"
jump origin
if bgr == 2:
define gui.main_menu_background = "gui/main_menu_B.png"
jump origin
label origin:
##define gui.main_menu_background = "gui/main_menu.png"
define gui.game_menu_background = "gui/game_menu.png"
The game will always show the last one (main_menu_B.png) as the background.
I also tried a renpy.random.randint(0, 2) fuction, but the game won't even make it to the main menu.
I know some C/C++ grammar, but I konw nothing about Python...
Or should I look into screen.rpy?
Last edited by xixikudo on Fri Jun 01, 2018 2:41 am, edited 1 time in total.
## Main Menu screen ############################################################
##
## Used to display the main menu when Ren'Py starts.
##
## https://www.renpy.org/doc/html/screen_special.html#main-menu
screen main_menu():
## This ensures that any other menu screen is replaced.
tag menu
style_prefix "main_menu"
$ bgr = renpy.random.randint(0, 2)
if bgr == 0:
add "gui/main_menu_O.png"
if bgr == 1:
add "gui/main_menu_1.png"
if bgr == 2:
add "gui/main_menu_2.png"
## Main Menu screen ############################################################
##
## Used to display the main menu when Ren'Py starts.
##
## https://www.renpy.org/doc/html/screen_special.html#main-menu
screen main_menu():
## This ensures that any other menu screen is replaced.
tag menu
style_prefix "main_menu"
$ bgr = renpy.random.randint(0, 2)
if bgr == 0:
add "gui/main_menu_O.png"
if bgr == 1:
add "gui/main_menu_1.png"
if bgr == 2:
add "gui/main_menu_2.png"
screen main_menu():
## This ensures that any other menu screen is replaced.
tag menu
style_prefix "main_menu"
$ bgr = renpy.random.randint(0, 2)
add "gui/main_menu_[bgr].png"
Just be mindful that originally xixikudo's image names have 0, B and R suffixes - which I know can be changed. However if you want to maintain the flexibility of different filenames, you can use renpy.random.choice: