[SOLVED] Inventory Imagebutton Help?

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
apcephalopod
Newbie
Posts: 4
Joined: Sat Apr 06, 2019 4:05 am
Contact:

[SOLVED] Inventory Imagebutton Help?

#1 Post by apcephalopod »

I'm trying to implement a clickable inventory system for the visual novel I'm making, and I'd like each inventory item to have a different image. This is how I'm trying to do so:

Code: Select all

screen invslots:
    frame:
        has vbox xalign 0.1 yalign 0.1
        label "{size=38}Inventory{/size}"
        text "[coins] Gold"
        vbox:
            for i in items:
                imagebutton "images/inv/inv_%s.png" % i.icon action SetVariable("invtext", "") 
            null height 20
            text invtext
        hbox:
            null width 300
            textbutton "Close" action Return()
        
label invscreen:
    call screen invslots
    return
Except I keep getting this error message:

Code: Select all

File "game/screens.rpy", line 1581: expected a keyword argument, colon, or end of line.
    imagebutton "images/inv/inv_%s.png" % i.icon action SetVariable("invtext", "") 
This happens no matter what I put after the %.

Here is how I defined my item class:

Code: Select all

init python:
    class Item:
        def __init__(self, name, desc, icon=False, cost, qty=0):
            self.name = name
            self.desc = desc
            self.icon = icon
            self.cost = cost
            self.qty = qty
        def change(self, name, desc, icon=False, cost):
            if name:
                self.name = name
            if desc:
                self.desc = desc
            if icon:
                self.icon = icon
            if cost:
                self.cost = cost
I'm not sure what I'm doing wrong. Every other part of the inventory system is working fine, and I can solve the problem by using textbuttons instead, but I'd like to avoid that if possible. Can someone help me fix this?
Last edited by apcephalopod on Wed Jul 08, 2020 4:30 pm, edited 1 time in total.

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Inventory Imagebutton Help?

#2 Post by RicharDann »

The error likely happens because of the way you're trying to interpolate i.icon into the name of the image file. That and you need to specify the idle property if you're not using auto. So try this instead:

Code: Select all

imagebutton idle "images/inv/inv_{}.png".format(i.icon) action SetVariable("invtext", "") 
The most important step is always the next one.

apcephalopod
Newbie
Posts: 4
Joined: Sat Apr 06, 2019 4:05 am
Contact:

Re: Inventory Imagebutton Help?

#3 Post by apcephalopod »

Thanks so much, it took a little tweaking but it worked! The path got added again if I left it in, so the new code looks like this:

Code: Select all

imagebutton: idle "{}".format(i.icon) hover "{}".format(i.icon) action SetVariable("invtext", i.desc)

Post Reply

Who is online

Users browsing this forum: No registered users