Ren'Py Changing the same image button in multiple ways

Alfius

Engaged Member
Modder
Sep 30, 2017
2,346
4,915
Renpy Noob again,

So I want to do two action on the same image for an image button.

This is the current code
Code:
    if imgname != "":
        imagebutton idle im.FactorScale(imgname, 0.15):
This is what I want to do to the image.
Code:
        im.FactorScale(imgname, 0.15)
        im.GrayScale(imgname)

While we are here. Can one do something like this?

Code:
                                if imgname != "":
                                    image smallimage = im.FactorScale(imgname, 0.15)
                                    imagebutton idle smallimage:
probably a stupid mistake, but I get an error

Code:
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.

File "game/Z Custom Status Bar Main.rpy", line 211: expected a keyword argument, colon, or end of line.
image smallimage = im.FactorScale(imgname, 0.15)
              
Ren'Py Version: Ren'Py 7.2.2.491
Tue Nov 10 19:28:59 2020
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
Can't you just nest the functions within each other?

imagebutton idle im.GrayScale( im.FactorScale( imgname, 0.15) ):
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,188
This is the current code
Code:
    if imgname != "":
        imagebutton idle im.FactorScale(imgname, 0.15):
Unless your images don't all have the same size, you don't need to do this. Giving a size to the image button should force Ren'py to resize the image.

So you should be able to achieve what you want with just :
Code:
    if imgname != "":
        imagebutton:
            idle im.GrayScale(imgname)
            xsize 100 ysize 100

While we are here. Can one do something like this?
Code:
                                if imgname != "":
                                    image smallimage = im.FactorScale(imgname, 0.15)
                                    imagebutton idle smallimage:
No, doing this is not possible. The image statement is proceeded at init level. So, "smallimage" will be defined, and defined once for all, before the game effectively start.


Can't you just nest the functions within each other?
It depend of what you do with the image, but normally it should works.
 
  • Like
Reactions: Alfius