Ren'Py AttributeError and I'm not sure what went wrong

iSleepZZZ

New Member
Aug 10, 2022
14
4
126
Hi guys, I'm not sure what did I do wrong. I defined a class object, and when I put it on a screen with:
Python:
screen display:
    text "[item.name]"
    text "[item.image]"
They show up on the screen just fine. However, when I put:
Code:
screen display:
    imagebutton:
    idle "images/[item.image].png"
It crashes the game and say [AttributeError("type object 'item' has no attribute 'image'")]
Did I miss something?

Here is the full code:

You don't have permission to view the spoiler content. Log in or register now.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
12,725
20,887
1,026
[...] to let you know that this answer has been answered by the french a few years ago: https://f95zone.to/threads/can-someone-help-me-with-inventory-solved.147164/post-10010237
And to extend my then answer, the error happen because idle "images/[item.image].png" is computed when the screen is created, early in the game life, while text "[item.image]" is computed each time the screen is displayed.

Solving the issue OP have is relatively easy:
Python:
init python:
    class item:
        def __init__(self, name, image):
            self.name = name
            self.image = "images/{}.png".format( image )
            self.imageName = image  # The code shown include its display as text, so...

screen backpack_display:
    hbox:
        xalign 0.5
        yalign 0.5
        for item in backpack:
            frame:
                vbox:
                    spacing 20
                    text "[item.name]"
                    text "[item.imageName]"
                    imagebutton:
                        idle item.image