[Solved] Is there a way I can make an image change like this (ConditionSwitch)?

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
nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

[Solved] Is there a way I can make an image change like this (ConditionSwitch)?

#1 Post by nanashine »

My game is based on a messenger system.

It looks like something like this:

Image

The big "avatar" image is shown by a screen.
And the small avatar inside the textbox is shown like this:

Code: Select all

        msg("{image=avatar} [name1]: Hi! How are you?", p=3, who=1)
The thing is that I wanted the avatar image to change according to the month. For example, if it's December, the avatar image would have a Christmas theme.

It's easy to do it with the big avatar image. Since it's a screen, I can use the if statement.

Something like:

Code: Select all

    if month in [1,2,3,4,5]:
        show image "jhon1avatar"
    
    if month in [6,7,8,9,10,11,]:
        show image "jhon2avatar"

    if month is [12]:
        show image "jhon3avatar"
But the smaller one, inside the message box code: {image=avatar}.

Is there a way I can declare this image and make it change according to the month?

Thanks.
Last edited by nanashine on Tue Apr 16, 2019 5:46 pm, edited 2 times in total.
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Is there a way I can make an image change like this?

#2 Post by Alex »

Try to make avatar image a dynamic one - https://www.renpy.org/doc/html/displaya ... splayables

nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

Re: Is there a way I can make an image change like this?

#3 Post by nanashine »

Alex wrote: Mon Apr 15, 2019 11:36 am Try to make avatar image a dynamic one - https://www.renpy.org/doc/html/displaya ... splayables
Oh, I didn't remember about that. Thank you! I'll give it a look :)
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

Re: Is there a way I can make an image change like this?

#4 Post by nanashine »

I did this:

Code: Select all

init:
    image avatar = ConditionSwitch(
            "month == '3'", "jhon1avatar.png",
            "month == '4'", "jhon2avatar.png",
            )
And I got this error:

Code: Select all

Exception: Switch could not choose a displayable.
I know there's something missing, but I don't know exactly what it is :?:
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Is there a way I can make an image change like this?

#5 Post by Matalla »

If the month is not 3 or 4, what image should show? Also, check if the place where the image is located is right (better use full path if you have any doubt). And, I'm not sure, but maybe the numbers shouldn't be between quotation marks.
Comunidad Ren'Py en español (Discord)
Honest Critique

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Is there a way I can make an image change like this?

#6 Post by Alex »

nanashine wrote: Tue Apr 16, 2019 12:14 pm

Code: Select all

init:
    image avatar = ConditionSwitch(
            "month == '3'", "jhon1avatar.png",
            "month == '4'", "jhon2avatar.png",
            )
Check the link - there should be "True" condition.

nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

Re: Is there a way I can make an image change like this?

#7 Post by nanashine »

I did:

Code: Select all

image avatar = ConditionSwitch (    
    "month == '3'","jhon1avatar.png",
    "month == '4'","jhon2avatar.png",
    "True", "jhon1avatar.png"
    )
It didn't gave me any errors. But even though we are on "month 4", it keeps using the default one (True) "jhon1avatar.png".
All examples I find, are used as sideimages, and they change according to a poiting system. So it's different from what I'm trying to do.
Maybe the code doesn't "understand" "month" in this case? It's like there's something still missing.

EDIT:
I removed the quotation marks and it is working now. These were the two problems: I had to remove the quotation and add "True".

Thank you so much guys! :)

Code: Select all

image avatar = ConditionSwitch (    
    "month == 3","jhon1avatar.png",
    "month == 4","jhon2avatar.png",
    "True", "jhon1avatar.png"
    )
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]