[Solved] SetVariable + animated image?

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

[Solved] SetVariable + animated image?

#1 Post by nanashine » Sun May 12, 2019 5:02 pm

I'm using a code like this to allow the player to choose some images like icons, etc.

Code: Select all

default iconjhon = '1'
image iconjhon:
        "icons/icon[iconjhon].png"
        pos (70,200)  
        

screen chooseiconjhon:

    textbutton '{size=30} Avatar{/size}' action SetVariable('iconjhon', '1'), Return() pos(50,240)

    textbutton '{size=30} Avatar{/size}' action SetVariable('iconjhon', '2'), Return() pos(215,240)
There's a part of my game where you receive a gift. This gift is an animated image. It will appear as a decoration item in a few scenes.
The problem is that this image will change according to which character your chose as your pair. For eg, if you chose Jhon it will be flowers. If you chose Adam it will be a cat, etc. But depending on which choice you make, you won't receive a gift hahah

So:

Code: Select all

screen receicedgift:
    add "gift"
    
label yourlivingroom12:
    
    scene livingroom
    show screen receicedgift
If you don't win any gift, the image "gift" keeps being an empty image (a transparent png).
If you win the flowers, "gift" should show the animated image of flowers.
If you win the cat, it would be the animated image of a cat.

The problem is that since the image is animated, I don't know how to use "SetVariable" to do that.
If the gift were a static image, I'd simply do it like the example above.

Like, if you chose Jhon, then I'd add a textbutton saying "you receive flowers from Jhon" with the action "SetVariable('gift', '1')", something like that.

Does anyone know how I can do it?

Thanks.
Last edited by nanashine on Mon May 13, 2019 1:54 pm, edited 1 time in total.
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

User avatar
Nagibator
Newbie
Posts: 16
Joined: Wed Jan 09, 2019 2:42 am
Contact:

Re: SetVariable + animated image?

#2 Post by Nagibator » Mon May 13, 2019 8:38 am

Probably not the answer you're looking for, but I think you can use if statements to choose which textbutton will show based off of who you chose.

As for if you want the button to do something specific, you can create a function in your init python that will do exactly what you want. Then just make the button use that function with:
action Function(yourFunctionNameHere)

Again, if this doesn't help, my sincerest apologies. My mind is a little scattered currently, but felt like attempting to be helpful.
Image

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

Re: SetVariable + animated image?

#3 Post by nanashine » Mon May 13, 2019 12:56 pm

Nagibator wrote:
Mon May 13, 2019 8:38 am
Probably not the answer you're looking for, but I think you can use if statements to choose which textbutton will show based off of who you chose.

As for if you want the button to do something specific, you can create a function in your init python that will do exactly what you want. Then just make the button use that function with:
action Function(yourFunctionNameHere)

Again, if this doesn't help, my sincerest apologies. My mind is a little scattered currently, but felt like attempting to be helpful.
Thank you so much! I'll give it a try :)
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

User avatar
Nagibator
Newbie
Posts: 16
Joined: Wed Jan 09, 2019 2:42 am
Contact:

Re: SetVariable + animated image?

#4 Post by Nagibator » Mon May 13, 2019 1:05 pm

nanashine wrote:
Mon May 13, 2019 12:56 pm
Thank you so much! I'll give it a try :)
No problem. Wishing the best for you.
Image

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

Re: SetVariable + animated image?

#5 Post by nanashine » Mon May 13, 2019 1:52 pm

Nagibator wrote:
Mon May 13, 2019 1:05 pm
nanashine wrote:
Mon May 13, 2019 12:56 pm
Thank you so much! I'll give it a try :)
No problem. Wishing the best for you.
Thank you!
I made it work in a odd way, but worked hah

I created the animated image, then:

Code: Select all

screen wongift:
    
        textbutton '{size=30}Show gift{/size}' action SetVariable('gift', 'cat') pos(10,10)


screen receivedgift:
    add gift


default gift= "empty.png"
Image "gift" is a default empty image (empty.png). And the screen "receivedgift" is always there. If you won something, the action SetVariable('gift', 'cat') pos(10,10) will turn de default into the gift you won. 'cat' being the animated image.

Now I just have to adjust it to look cool, but it's working hahah

Thank you for your idea too.
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

User avatar
Nagibator
Newbie
Posts: 16
Joined: Wed Jan 09, 2019 2:42 am
Contact:

Re: SetVariable + animated image?

#6 Post by Nagibator » Mon May 13, 2019 5:47 pm

nanashine wrote:
Mon May 13, 2019 1:52 pm
Now I just have to adjust it to look cool, but it's working hahah

Thank you for your idea too.
Good to know. And you're welcome. :)
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]