Attribute Error: 'tuple' object has no attribute 'img' [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
KataMata
Newbie
Posts: 9
Joined: Thu Jan 28, 2021 3:55 pm
Contact:

Attribute Error: 'tuple' object has no attribute 'img' [Solved]

#1 Post by KataMata »

I'm attempting to make a gift inventory that would display multiple gifts at once and when clicked on would show how much you had, the name of the gift and a description. This isn't exactly working as I can't even get it to display the Right imagebutton. It's not that I'm putting in the image wrong as much as it can't seem to find it. The error will pop up upon opening the gift menu.

The Inventory Code

Code: Select all

        grid 15 6:
            xpos -791
            ypos -445
            spacing 2
            for giftItem in giftList:
                frame:
                    xmaximum 120
                    ymaximum 120
                    imagebutton idle giftItem.img hover giftItem.hove action None
            for i in range(len(giftList), 90):
                frame:
                    xmaximum 120
                    ymaximum 120
                    imagebutton idle "ErrorGift.png" action None
Gift Class

Code: Select all

    class giftItem(object):

        def __init__(self, name, img, hove, desc, amount, got):
            self.name = name
            self.img = img
            self.hove = hove
            self.desc = desc
            self.amount = amount
            self.got = got
Code that adds it into the GiftList (GiftList is an empty list at the start)

Code: Select all

    $ giftList.append(("Strawberry Milk", "strawmilk.png", "ErrorGift.png", "Pink colored milk.", 0, 0))
I'm guessing the reason it can't find the img attribute is because of how it's added to the GiftList, but I don't know how to fix that.

What do I need to change with the code to make it where it can find the attributes?
Last edited by KataMata on Tue Feb 16, 2021 12:33 am, edited 1 time in total.

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Attribute Error: 'tuple' object has no attribute 'img'

#2 Post by gas »

Is the way you're creating the object that doesn't work.
Create the object and then add it to the list.

The way you're doing you're not appending an object, but a tuple made of such values (that obviously don't have parameters).

Code: Select all

default milkshake = giftItem(**params)
$ giftList.append(milkshake)
Please notice the 'default'. As instances are not saved if created at runtime, to keep your game consistent between saves you MUST declare them as default, so "before the game begin". That shouldn't be hard for an inventory (you already know all objects that will figure in your game in advance).
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

KataMata
Newbie
Posts: 9
Joined: Thu Jan 28, 2021 3:55 pm
Contact:

Re: Attribute Error: 'tuple' object has no attribute 'img'

#3 Post by KataMata »

Yeah that fixed it, the only problem I can see is with reloading where it won't rerun the append parts, but that Doesn't seem to come up when playing normally with Saves so it should be good. Thank you for the help.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Majestic-12 [Bot]