How to move an item between Inventory and Equipment system in RPG style

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
mantissocks
Newbie
Posts: 1
Joined: Tue Apr 05, 2022 10:27 pm
Contact:

How to move an item between Inventory and Equipment system in RPG style

#1 Post by mantissocks » Tue Apr 05, 2022 11:09 pm

So I was watching Elaine's youtube tutorial https://www.youtube.com/watch?v=leEiOzuVpTc

and I followed through all of the steps of making the inventory system in my RPG game. (Big thanks to her!)

But one thing was, I was wondering how I can move an item from the inventory to equipment with just a click? In her video, =after pressing the image button of the item, it opens up a menu that has equip and discard functions. But I wanted the system to show description when I hover over the equipment, and move it to the equipment tab when I click it. I played other similar ren'py games that can do this and I really wanted to know how.

I don't want to post her whole code here, just that the big inventory is a class, mainly with "equipable" and "consumable" as subclasses, with some stats. inventory is a list, and player equipment tab is in the player class, with the part that equipping an armor changes your stats. And she uses a "selected item" variable to pass the data of the item. I don't want it to be 2 buttons in total and I don't want the icon to stay in the inventory after moving it to the equipment tab.

For now I thought of two ways: using the "selected item" variable but combine the action of the two buttons(equip and then remove from inventory) and then setting it to None at the end, it didn't really work because there are error when the "selected_item" is None. but I put the selected_item in the beginning of the button action, so I don't really know how it works.

The second one just removes the selected_item variable, and replace it with something like player.armor["chest"] (then unequip and append it to the inventory), there's no error this time, but the equipment keeps duplicating themselves, every time you click there's a new duplicate. Even hovering sometimes duplicates it in the inventory.

Then I looked into the console, and I see that the length of the inventory is stranger, I originally have 3 items in my inventory, I put 2 in my equipment, and now the length of the inventory is 3, while I can see 14 icons of the same items.

I have been working on the system for 12 hours non-stop, it seemed so easy at first but I really wanted to know about the secret behind moving a picture and then moving it back. This is my first time using python and although maybe I'm still too ambitious, I still wish to learn more about renpy and python. I'll post the associated codes if anyone wants to help! Thanks a lot~

Image

jeffster
Regular
Posts: 123
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: How to move an item between Inventory and Equipment system in RPG style

#2 Post by jeffster » Sat Apr 09, 2022 5:03 pm

Basically there are 2 lists. (Inventory and Equipped.)

Items there are represented as buttons. (The same images and tooltips in both lists.)

Clicking such button should remove its item from its current list and add it to another list:

Code: Select all

default list_1 = ["item_1", "item_2"]
default list_2 = []
define tooltips = {"item_1": "This is a fork", "item_2": "This is a cork", }
screen show_2_lists():
    frame:
        pos (0, 0)
        ysize 120
        hbox:
            for i in list_1:
                imagebutton:
                    auto "".join(("images/items/", i, "_%s.png"))
                    tooltip tooltips[i]
                    action [
                        RemoveFromSet(list_1, i),
                        AddToSet(list_2, i),
                        renpy.restart_interaction
                    ]

    frame:
        pos (0, 900)
        ysize 120
        hbox:
            for i in list_2:
                imagebutton:
                    auto "".join(("images/items/", i, "_%s.png"))
                    tooltip tooltips[i]
                    action [
                        RemoveFromSet(list_2, i),
                        AddToSet(list_1, i),
                        renpy.restart_interaction
                    ]
Of course if your items are in some complex data structures or structured pictures then moving them or showing them you might need to use some other functions, but the general idea should be the same.

Post Reply

Who is online

Users browsing this forum: enaielei