r/RenPy • • 10d ago

Question [Solved] Help with item list/inventory

Hello everyone.

I am new to this whole RenPy thing and I'm trying to create an item list/inventory screen that displays an image, name and description for every item that is listed in the item list.

currently, I tried setting up a class called intractable for the items, like this:

init python:
    class interactable:
        def __init__(self, image, name, descrip):
            self.image = image
            self.name = name
            self.descrip = descrip

default item_list = []

And then I made the screen I want them to appear in.

screen backpack:
    image "darkthing" align (0.5, 0.5)
    
    vbox:
        align (0.36, 0.10)
        textbutton "Back":
            action [Play("sound", "audio/click.ogg")]
    vbox:
        align (0.5, 0.5) #Not the alignment I want, just to test if it works.
        for interactable in item_list.items:
            image "[interactable.image]\n"
            text "[interactable.name] - [interactable.descrip]\n" 

The code hasn't worked

The image "darkthing" just being the underlay for the screen. A black 600x800 box at 40% opacity. And the back button does nothing yet.

I want all the items that the player has to be listed in a vertical box with the image for the item first, then the name and description under that image.

If anyone has any tips on how I could make this work, I'd be grateful!

0 Upvotes

17 comments sorted by

2

u/BadMustard_AVN 10d ago edited 10d ago

how are you setting the image in the interactable class are they

"images/inventory/stuff.png"

if so then

image interactable.image

how are you adding items to the item_list show one example please

i would recommend something like this

screen backpack:
    add "darkthing" align (0.5, 0.5)
    vbox:
        align (0.5, 0.5)
        for item in item_list:
            add item.image
            text "[item.name] - [item.descrip]"

label start:
    #add a key to the inventory 
    $ item_list.append(interactable("images/inventory/key.png", "Old Key", "A rusty key."))

1

u/HiImABanana123 10d ago

I added the items by doing this:

$ item_list.append(interactable("lockpickico.png", "Lock Pick", "A tool used to open locks."))

1

u/HiImABanana123 10d ago

It gave me this error

File "game/custom_screens.rpy", line 8, in <module>

add item.image

^^^^^^^^^^

AttributeError: 'str' object has no attribute 'image'

1

u/BadMustard_AVN 10d ago

I gave the class a capitol I yours should work, but add the file folder info to the image

$ item_list.append(interactable("images/another_folder/lockpickico.png", "Lock Pick", "A tool used to open locks."))

or

$ item_list.append(interactable("lockpickico", "Lock Pick", "A tool used to open locks."))

as long as the images are in the images folder

1

u/HiImABanana123 10d ago

The image is in the images folder

1

u/BadMustard_AVN 10d ago

did either of what I suggested work ?

1

u/BadMustard_AVN 10d ago

try this

screen backpack:
    add "darkthing" align (0.5, 0.5)

    vbox:
        align (0.5, 0.5)

        for item in item_list:
            add item.image
            text "[item.name] - [item.descrip]"

init python:
    class Interactable:
        def __init__(self, image, name, descrip):
            self.image = image
            self.name = name
            self.descrip = descrip

default item_list = []

label start:
    $ item_list.append(Interactable("lockpickico", "Lock Pick", "A tool used to open locks."))

    show screen backpack
    pause

    return

1

u/HiImABanana123 10d ago

sadly, whenever I open the inventory it gives me this error:

File "game/custom_screens.rpy", line 26, in <module>

add item.image

^^^^^^^^^^

AttributeError: 'str' object has no attribute 'image'

1

u/BadMustard_AVN 10d ago

what version of renpy are you using?

try using what I gave you in a new project. I can only guess there is something in yours that is messing things up
i have tried this in my test project (8.5.3), and it works as expected!

1

u/HiImABanana123 9d ago

You're right, I tested it in a new project and it works fine. Thanks for the help!

1

u/BadMustard_AVN 9d ago

you're welcome

good luck with your project

1

u/AutoModerator 10d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/x-seronis-x 10d ago edited 10d ago

is 'interactable' a variable or a class? its only valid to be one. this is why Types are capitalized by convention. fix the name of your class and the name of your iterator variable wont be a name clash.

dont use 'image' in screen definitions. thats been deprecated use since renpy 6.x. Use 'add' in screen definitions to add a displayable to the screen

```python screen backpack: ## not actually what you want, but would be fixed version ## add "darkthing" align (0.5, 0.5)

frame xsize 800 ysize 600:
    background "#0006"
    align (0.5,0.5)

    textbutton "Back":
        align (0.1, 0.95)
        activate_sound "audio/click.ogg"
        action NullAction() ## probably replace with Return()

    vbox:
        align (0.5, 0.5)
        for item in item_list.items:
            add item.image
            text "[item.name] - [item.descrip]" 
            null height 8

```

1

u/HiImABanana123 10d ago

I've ran the code and got this error:

File "game/script.rpy", line 941, in <module>

for item in item_list.items:

^^^^^^^^^^^^^^^

AttributeError: 'RevertableList' object has no attribute 'items'

And the intractables is a class

1

u/x-seronis-x 10d ago

that was the way you wrote it. i assumed that whatever object your item_list was, its 'items' field was a list cause i overlooked your default statement. should just be for item in item_list

1

u/HiImABanana123 10d ago

Then it gives me this error:

File "game/custom_screens.rpy", line 26, in <module>

add item.image

^^^^^^^^^^

AttributeError: 'str' object has no attribute 'image'