imagebutton using a variable as its image [SOLVED]

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
vociferocity
Regular
Posts: 93
Joined: Sat Jun 12, 2010 11:27 am
Projects: Rogue of Heart, Valkyrie
Contact:

imagebutton using a variable as its image [SOLVED]

#1 Post by vociferocity »

so I'm trying to write in some dynamic imagebuttons for my inventory that will show the item at each slot, regardless of the item, but I'm getting an error that says:
TypeError: not all arguments converted during string formatting

Code: Select all

imagebutton auto "[a_Inventory[0][3]]" action [ SetVariable('s_Message', a_Inventory[0][2]), Show('displaymessage') ]
that's my imagebutton code, and it works perfectly fine when instead of

Code: Select all

"[a_Inventory[0][3]]"
I have the actual filepath, but I'm not sure what the problem is with writing it like this

edit: in case anyone's interested, I solved my problem! originally, my code was like this:

Code: Select all

a_Inventory[0][3] = "art/inventory/bluehat_%s.png"
imagebutton auto "[a_Inventory[0][3]]" etc
which wasn't working! what does work, however, is this:

Code: Select all

$ im_bluehat = "art/inventory/bluehat_%s.png"
a_Inventory[0][3] = im_bluehat
imagebutton auto a_Inventory[0][3]
Last edited by vociferocity on Sun Feb 26, 2012 8:59 am, edited 2 times in total.

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

Re: imagebutton using a variable as its auto

#2 Post by Alex »

As it said in documentation, "auto" property should looks like <auto "save_%s.png">. So you have a variable to set the first part of image name used for button, but you've missed the rest part of it.
Try <auto "[a_Inventory[0][3]]_%s.png">, if images named like "apple_idle.png", "orange_hover.png" etc.
(not tested)

vociferocity
Regular
Posts: 93
Joined: Sat Jun 12, 2010 11:27 am
Projects: Rogue of Heart, Valkyrie
Contact:

Re: imagebutton using a variable as its auto

#3 Post by vociferocity »

oh, the variable in question is actually set to

Code: Select all

"art/inventory/bluehat_%s.png"
, which works fine when I c/p it into the auto section instead of just calling the variable, so I don't think that's the problem

Post Reply

Who is online

Users browsing this forum: Google [Bot]