Add a random image to a screen

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
User avatar
Keinart
Regular
Posts: 133
Joined: Sun May 13, 2012 8:28 pm
Completed: One Thousand Lies
Projects: Lotus Reverie
Organization: Keinart Lobre
Tumblr: keinart
itch: keinart
Location: Spain
Contact:

Add a random image to a screen

#1 Post by Keinart » Tue Mar 15, 2016 3:37 pm

It is possible to add a random image to a menu screen? Basically I have a set of images and I want to use the Add function to display only ONE of them, randomly. So basically everytime the user opens that menu screen he will see a different image everytime.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Add a random image to a screen

#2 Post by xela » Tue Mar 15, 2016 4:27 pm

You have no idea how many answers to this question there are on this forum already... :D
Like what we're doing? Support us at:
Image

User avatar
Keinart
Regular
Posts: 133
Joined: Sun May 13, 2012 8:28 pm
Completed: One Thousand Lies
Projects: Lotus Reverie
Organization: Keinart Lobre
Tumblr: keinart
itch: keinart
Location: Spain
Contact:

Re: Add a random image to a screen

#3 Post by Keinart » Tue Mar 15, 2016 4:30 pm

xela wrote:You have no idea how many answers to this question there are on this forum already... :D
I've been looking for it for a while and couldn't find it, would you mind giving a hand?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Add a random image to a screen

#4 Post by xela » Tue Mar 15, 2016 4:42 pm

Like what we're doing? Support us at:
Image

User avatar
Keinart
Regular
Posts: 133
Joined: Sun May 13, 2012 8:28 pm
Completed: One Thousand Lies
Projects: Lotus Reverie
Organization: Keinart Lobre
Tumblr: keinart
itch: keinart
Location: Spain
Contact:

Re: Add a random image to a screen

#5 Post by Keinart » Tue Mar 15, 2016 4:49 pm

xela wrote:http://lemmasoft.renai.us/forums/search ... background

Or try different searchwords...
I've already did that, but none of the solutions there are working for me. I've already tried different things, the one that seems to work better is this one:

Code: Select all

    add renpy.random.choice(["imageone.png", "imagetwo.png", "imagethree.png"])
The issue is that I'm trying to do this in the preferences menu, and then when I change ANYTHING in the menu, let it be move the sound bar or change from window to full screen mode or anything like that, the image is changed again (in fact it changes a for every little movement I do in the sound bar for example, what is kinda funny). I need something that picks one imagen for the screen and keeps it until I leave the screen and come back again.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Add a random image to a screen

#6 Post by xela » Tue Mar 15, 2016 5:14 pm

How about:

Code: Select all

screen scr():
    default img = renpy.random.choice(["imageone.png", "imagetwo.png", "imagethree.png"])
    add img
?
Like what we're doing? Support us at:
Image

User avatar
Keinart
Regular
Posts: 133
Joined: Sun May 13, 2012 8:28 pm
Completed: One Thousand Lies
Projects: Lotus Reverie
Organization: Keinart Lobre
Tumblr: keinart
itch: keinart
Location: Spain
Contact:

Re: Add a random image to a screen

#7 Post by Keinart » Tue Mar 15, 2016 5:21 pm

xela wrote:How about:

Code: Select all

screen scr():
    default img = renpy.random.choice(["imageone.png", "imagetwo.png", "imagethree.png"])
    add img
?
Ahh, it works. I knew I wasn't thinking correctly, I just had to put a new screen inside the screen, that makes sense. Thank you for the help!

Post Reply

Who is online

Users browsing this forum: No registered users