[SOLVED] Slide Show with different jpg-files

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
Wink3319
Newbie
Posts: 3
Joined: Thu Feb 15, 2024 3:52 pm
Contact:

[SOLVED] Slide Show with different jpg-files

#1 Post by Wink3319 »

Hi,

I am working on a game for my daughter. It is quite simple: I create random additions and let her give the answer. If the answer is Right, she gets a point, if not then not. All this is easy and good and well. Now, I want to show different pictures - like a slide show depending on her answer. So, if she answers wrong, there is a pictire for "wrong" and if she answers right, I want to select a picture randomly to show for "success". This should keep her interest in getting the answers right.

Here is my question:

Can I dynamically change the content of a given image? I know how to define a given image and how to show it on screen. But I am struggling trying to change the content (that is the jpg-file) of the image during the game. I can do the following:

image pic_good_0 = im.Scale("Gut_01.jpg", 1920, 1080)
image pic_good_1 = im.Scale("Gut_02.jpg", 1920, 1080)
image pic_good_2 = im.Scale("Gut_03.jpg", 1920, 1080)
image pic_good_3 = im.Scale("Gut_04.jpg", 1920, 1080)
image pic_good_4 = im.Scale("Gut_05.jpg", 1920, 1080)
image pic_good_5 = im.Scale("Gut_06.jpg", 1920, 1080)
image pic_good_6 = im.Scale("Gut_07.jpg", 1920, 1080)
image pic_good_7 = im.Scale("Gut_08.jpg", 1920, 1080)
image pic_good_8 = im.Scale("Gut_09.jpg", 1920, 1080)

and so on. I can then do a random integer to go into a series of if and elif statements to select, which image to show. But, that seems a bit heavy handed. Can I somehow dynamically create images that point to different jpg-files and change that jpg-file of a given image that I want to show. I couldn't find a way. Is there a way?

Thank you for your help!
Last edited by Wink3319 on Sat Feb 17, 2024 3:44 am, edited 1 time in total.

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Slide Show with different jpg-files

#2 Post by m_from_space »

Wink3319 wrote: Thu Feb 15, 2024 4:00 pm Hi,

I am working on a game for my daughter. It is quite simple: I create random additions and let her give the answer. If the answer is Right, she gets a point, if not then not. All this is easy and good and well. Now, I want to show different pictures - like a slide show depending on her answer. So, if she answers wrong, there is a pictire for "wrong" and if she answers right, I want to select a picture randomly to show for "success". This should keep her interest in getting the answers right.

Here is my question:

Can I dynamically change the content of a given image?
That's such a nice little idea, doing something unique for your kid I mean.

There are multiple ways to do what you want, the easiest way would be to use Renpy's internal ATL system. Make sure to hide the screen after showing it. Only re-showing it will re-select a new picture.

Code: Select all

image random_pic_good:
    choice:
        "pic_good_0"
    choice:
        "pic_good_1"
    choice:
        "pic_good_2"

screen result():
    if answer_is_correct:
        add "random_pic_good"
    else:
        add "pic_wrong"

Wink3319
Newbie
Posts: 3
Joined: Thu Feb 15, 2024 3:52 pm
Contact:

Re: Slide Show with different jpg-files

#3 Post by Wink3319 »

Hi! Thank you very much for the feedback! I will try this out. Just to make sure: "pic_good_0", "pic_good_1" and so on, would be the file names to fill image random_pic_good, correct? So; i toss random_pic_good on the screen and then it choses between all the files that I put under the choice: property?

Is there a way to combine this with the sizing of the image using im.Scale?

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Slide Show with different jpg-files

#4 Post by m_from_space »

Wink3319 wrote: Thu Feb 15, 2024 5:16 pmSo; i toss random_pic_good on the screen and then it choses between all the files that I put under the choice: property?
Exactly.
Is there a way to combine this with the sizing of the image using im.Scale?
You don't have to use im.Scale at all to be honest, it's deprecated anyway - I actually cannot even find an entry for it here: https://www.renpy.org/doc/html/im.html
The use of image manipulators is historic. A number of image manipulators that had been documented in the past should no longer be used, as they suffer from inherent problems, and in general (except for im.Data()), the Transform() displayable provides similar functionality while fixing the problems.
Use Frame() instead:

Code: Select all

image random_pic:
    choice:
        "Gut_01"
    choice:
        "Gut_02"
    ...
    
screen result():
    ...
        # automatically stretches the picture to the size of the parent (in this case the whole screen)
        add Frame("random_pic")

Wink3319
Newbie
Posts: 3
Joined: Thu Feb 15, 2024 3:52 pm
Contact:

Re: [SOLVED] Slide Show with different jpg-files

#5 Post by Wink3319 »

Hi, I implemented your recommendation. It works like a charm. Thank you for your support!

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]