[Solved] How to set image, for an imagebutton, using image variable?

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
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

[Solved] How to set image, for an imagebutton, using image variable?

#1 Post by henvu50 »

I need to set an image for the imagebutton using an image variable. I can't figure it out though. The renpy documentation doesn't show any example either. I think maybe it's not possible?

Code: Select all

# I tried so many things, i know the following is commented out
# $ testAutoDeclaredThisWay = im.FactorScale("test_%s.png", 3)
image testIdle = im.FactorScale("test_idle.png", 2)
image testHover = "test_hover.png"
image testAuto = "test_%s.png"

screen pissed():
     imagebutton:
       # can someone explain the science behind using an image variable here?
       # idle testIdle 
       # hover testHover 
       # auto testAuto 
       # testAutoDeclaredThisWay 
       # auto "[testAuto]"
       focus_mask True
       action Jump ("off a cliff ...")
This link only shows one example of imagebutton being used and it's using a string, not an image variable.
https://www.renpy.org/doc/html/screens.html#imagebutton

Code: Select all

screen gui_game_menu():
     vbox xalign 1.0 yalign 1.0:
          # is it not possible to use an image variable here?
          imagebutton auto "save_%s.png" action ShowMenu('save')
          imagebutton auto "prefs_%s.png" action ShowMenu('preferences')
          imagebutton auto "skip_%s.png" action Skip()
          imagebutton auto "afm_%s.png" action Preference("auto-forward mode", "toggle")
Last edited by henvu50 on Sat Jun 12, 2021 10:52 pm, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How to set image, for an imagebutton, using image variable?

#2 Post by Ocelot »

image is just that. A concrete image, a single displayable which can be shown. image testAuto = "test_%s.png" makes no sense unless your OS supports having % in filenames.

auto property of imagebuttons does not take images or displayables unlike other properties. It takes a string with percentile substititution marker, interpolates different words instead of that marker and tries to resolve resulting strings as image names.

Code: Select all

image btn_idle = "button_idle.png"
image btn_hover = "button_hover.png"

image btn_big_idle = im.FactorScale(btn_idle, 2)
image btn_big_hover = im.FactorScale(btn_hover, 2)

default btn_auto = "btn_%s"

screen button_test():
    imagebutton auto btn_auto action Jump("endgame")

label start:
    python:
        input = renpy.input("Enter + to have big buttons")
        if input == '+':
            btn_auto = "btn_big_%s"
    call screen button_test

label endgame:
    return

< < insert Rick Cook quote here > >

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: How to set image, for an imagebutton, using image variable?

#3 Post by henvu50 »

Ocelot wrote: Sat Jun 12, 2021 2:44 am image is just that. A concrete image, a single displayable which can be shown. image testAuto = "test_%s.png" makes no sense unless your OS supports having % in filenames.

auto property of imagebuttons does not take images or displayables unlike other properties. It takes a string with percentile substititution marker, interpolates different words instead of that marker and tries to resolve resulting strings as image names.

Code: Select all

image btn_idle = "button_idle.png"
image btn_hover = "button_hover.png"

image btn_big_idle = im.FactorScale(btn_idle, 2)
image btn_big_hover = im.FactorScale(btn_hover, 2)

default btn_auto = "btn_%s"

screen button_test():
    imagebutton auto btn_auto action Jump("endgame")

label start:
    python:
        input = renpy.input("Enter + to have big buttons")
        if input == '+':
            btn_auto = "btn_big_%s"
    call screen button_test

label endgame:
    return

Aaah i get it now! Thanks!

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]