Ren'Py Call screen with random picture.[SOLVED]

Deleted member 416612

The 'landlord'
Donor
Game Developer
Feb 2, 2018
923
3,925
Hi mates,

I am trying to add a screen that will show a random picture from a series. For example in free-roaming, when a user will navigate to a location, then a random picture will be shown and if the same user will navigate again to that screen, another random picture is shown, from the same series.

Can anyone help me with a hint?

Cheers
 

Brasdf

New Member
Aug 28, 2018
14
19
You can use "renpy.random.choice(seq) => Return a random element from the non-empty sequence seq".

Python:
randPicture = renpy.random.choice(['pic1.png', 'pic2.jpg', 'mypic.gif'])

Than, just use the variable randPicture to display the random picture.

 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,188
Can anyone help me with a hint?
Like Brasdf said, the first part of the answer is in renpy.random.choice. It will choice randomly one of the entry in the list you pass as parameter.

Then, the second part of the answer is in the default screen statement. It assign a value to a screen variable, but will not update it when the screen will be refreshed. This let you define randomly the background, and keep it consistent until the screen is hidden/replaced. Then when you'll show/call it again, a new image will be selected for the background.

Code:
# List of the possible background for the location "here"
define hereRndImage = [ "image1.jpg", "image2.jpg", "image3.jpg" ]
# same for the location "there"
define thereRndImage = [ "image4.jpg", "image5.jpg", "image6.jpg" ]

# screen for the location "here"
screen locationHere():

    default bground = renpy.random.choice( hereRndImage )

    add bground
    [...]
Obviously, there's a lot of possible variations around that.
 
  • Like
Reactions: Brasdf and Rich
Nov 26, 2018
46
22
Riddle me this:
I added this to renpy and it gave me this error:

PARSING THE SCRIPT FAILED
file "game/script.rpy, line 76: expected statement
randPicture -> = renpy.random.choice(['image.01.jpg', 'image02.jpg', 'image03.jpg'])
whereas the -> above is a red arrow.