Page 1 of 1
Help with Imagebuttons and variables
Posted: Thu Apr 15, 2021 6:22 am
by GeeSeki
I'm have 3 variables that pull a random gift from a list. For example:
Code: Select all
giftoftheday_1 = "gift001"
giftoftheday_2 = "gift002"
giftoftheday_3 = "gift003"
I'm trying to get the imagebutton to display based on which gift is chosen but renpy can't read the button.
Code: Select all
screen scr_test():
imagebutton auto "btn [giftoftheday_1]_%s" xpos 1260 ypos 120 focus_mask True action Call("lbl_buy_[giftoftheday_1]")
imagebutton auto "btn [giftoftheday_2]_%s" xpos 1260 ypos 340 focus_mask True action Call("lbl_buy_[giftoftheday_2]")
imagebutton auto "btn [giftoftheday_3]_%s" xpos 1260 ypos 560 focus_mask True action Call("lbl_buy_[giftoftheday_3]")
I won't get the value inside the btn name. It'll always say it can't find "btn [giftoftheday_1]_idle" rather than reading it as "btn gift001_idle"
Re: Help with Imagebuttons and variables
Posted: Thu Apr 15, 2021 6:36 am
by Ocelot
String substitution does not work in filenames. You need to construct string manually:
Code: Select all
screen scr_test():
python:
gotd_file1 = "btn " + giftoftheday_1 + "_%%s" #Use double percentage sign to avoid treating it as a substitution marker
gotd_file2 = "btn " + giftoftheday_2 + "_%%s"
gotd_file3 = "btn " + giftoftheday_3 + "_%%s"
imagebutton auto gotd_file1 xpos 1260 ypos 120 focus_mask True
IIRC text suibstitution won't work on label names either, so you will propably have to do same thing for Call actions.
Re: Help with Imagebuttons and variables
Posted: Thu Apr 15, 2021 6:57 am
by GeeSeki
Ocelot wrote: ↑Thu Apr 15, 2021 6:36 am
String substitution does not work in filenames. You need to construct string manually:
Code: Select all
screen scr_test():
python:
gotd_file1 = "btn " + giftoftheday_1 + "_%%s" #Use double percentage sign to avoid treating it as a substitution marker
gotd_file2 = "btn " + giftoftheday_2 + "_%%s"
gotd_file3 = "btn " + giftoftheday_3 + "_%%s"
imagebutton auto gotd_file1 xpos 1260 ypos 120 focus_mask True
IIRC text suibstitution won't work on label names either, so you will propably have to do same thing for Call actions.
Thank you for that! That worked but I also needed to have the buttons resized so I used this instead:
Code: Select all
screen scr_test():
imagebutton auto "btn giftoftheday_1_%s" xpos 1260 ypos 120 focus_mask True action [SetVariable("giftclick",1), Call("lbl_buy_gift")]
imagebutton auto "btn giftoftheday_2_%s" xpos 1260 ypos 340 focus_mask True action [SetVariable("giftclick",2), Call("lbl_buy_gift")]
imagebutton auto "btn giftoftheday_3_%s" xpos 1260 ypos 560 focus_mask True action [SetVariable("giftclick",3), Call("lbl_buy_gift")]
image btn giftoftheday_1_hover:
"//images/gifts/btn_giftitem_[giftoftheday_1]_hover.png"
zoom 0.5
image btn giftoftheday_1_idle:
"//images/gifts/btn_giftitem_[giftoftheday_1]_idle.png"
zoom 0.5
image btn giftoftheday_2_hover:
"//images/gifts/btn_giftitem_[giftoftheday_2]_hover.png"
zoom 0.5
image btn giftoftheday_2_idle:
"//images/gifts/btn_giftitem_[giftoftheday_2]_idle.png"
zoom 0.5
image btn giftoftheday_3_hover:
"//images/gifts/btn_giftitem_[giftoftheday_3]_hover.png"
zoom 0.5
image btn giftoftheday_3_idle:
"//images/gifts/btn_giftitem_[giftoftheday_3]_idle.png"
zoom 0.5
label lbl_buy_gift:
if giftclick == 1:
$ gift_inventory.append(giftoftheday_1)
$ money -= giftprice_1
elif giftclick == 2:
$ gift_inventory.append(giftoftheday_2)
$ money -= giftprice_2
else:
$ gift_inventory.append(giftoftheday_3)
$ money -= giftprice_3
call screen scr_market_sequence