VN Ren'Py Need help with Renpy Inventory Variable Display

MaxGamez

Newbie
Game Developer
Jan 24, 2023
93
175
I want to create a Simple Inventory system which shows the item name and quantity in virtual box if the item value is greater than 0, in ascending/descending order of quantity/name (if that is possible).
Python:
init python:
    
    class inventory():
        def __init__(self, items, qty):
            self.items = items
            self.qty = qty

        def add_item(self, item):
            self.items.append(item)
            self.qty += 1   

        def remove_item(self, item):
            self.items.remove(item)
            self.qty -= 1

        def list_items(self):
            if len(self.items) < 1:
                for item in self.items:
                    print(item.name)
            
    class inventoryitem():
        def __init__(self, name, desc):
            self.name = name
            self.desc = desc
This is pure python so to display in it a virtual box I would need pure python statement which I am not sure how to do it in this code, where if possible items should be displayed in ascending/descending order of quantity/name .
Python:
screen inventory_screen():
    frame:
        xalign 0.5
        yalign 0.5
        vbox:
            xalign 0.5
            yalign 0.5
            text "virtual box."
 

MaxGamez

Newbie
Game Developer
Jan 24, 2023
93
175
Please share a code with these simple functions, it will help other people who are struggling with inventory management just like me.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
I want to create a Simple Inventory system which shows the item name and quantity in virtual box if the item value is greater than 0, in ascending/descending order of quantity/name (if that is possible).
And none of the dozen threads regarding inventories for Ren'Py helped you ? Surprising, really surprising...


Python:
        def add_item(self, item):
            self.items.append(item)
            self.qty += 1
What "qty" is supposed to mean ? It's not the quantity for that item since it's a global value for the inventory, and there's no interest to have an attribute to know how many objects there's in the inventory since len( self.items ) already do it.


This is pure python so to display in it a virtual box I would need pure python statement [...]
For what reason ?


Python:
# Forced to use "ivt" (or in fact whatever name) since "inventory" is already used by the class.
default ivt = inventory()

screen inventory_screen():
    frame:
        xalign 0.5
        yalign 0.5
        vbox:
            xalign 0.5
            yalign 0.5
            # Basic viewport, there's other way to handle this.
            vpgrid:
                row 2
                #  Browse all items in the inventory
                for item in ivt.items:
                    # And display their name and description
                    text [item.name]
                    text [item.desc]
I would have liked to answer the exact question, and therefore filter when the item value is 0 and sort the items accordingly to their quantity, but your code do not count the quantity for each item...

You should really use the site's search feature, and look at the threads I talked about above. They have functional inventory systems.
 

MaxGamez

Newbie
Game Developer
Jan 24, 2023
93
175
And none of the dozen threads regarding inventories for Ren'Py helped you ? Surprising, really surprising...




What "qty" is supposed to mean ? It's not the quantity for that item since it's a global value for the inventory, and there's no interest to have an attribute to know how many objects there's in the inventory since len( self.items ) already do it.




For what reason ?


Python:
# Forced to use "ivt" (or in fact whatever name) since "inventory" is already used by the class.
default ivt = inventory()

screen inventory_screen():
    frame:
        xalign 0.5
        yalign 0.5
        vbox:
            xalign 0.5
            yalign 0.5
            # Basic viewport, there's other way to handle this.
            vpgrid:
                row 2
                #  Browse all items in the inventory
                for item in ivt.items:
                    # And display their name and description
                    text [item.name]
                    text [item.desc]
I would have liked to answer the exact question, and therefore filter when the item value is 0 and sort the items accordingly to their quantity, but your code do not count the quantity for each item...

You should really use the site's search feature, and look at the threads I talked about above. They have functional inventory systems.
well, I used code from this video and I am new to coding, I tried bunch of tutorials but still didn't get what I was looking for, what I need specifically is to display item name and no. of items if the items is not empty.
There are tutorials where images are used to display the contents which looks complex to me, so I needed a simpler version.
Plus my wordings I used for pure python may not be correct since I used wordings from that video.
I would like to know the code for displaying the Inventory data in a box, I can do the rest of the codes looking at tutorials.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,191
I used code from this video
Oh god... You really copied the whole code :eek:

This tutorial is either the most stupid way to use a list, or an easy way to looks smart to the eyes of people who know nothing, but in no way this is a tutorial for an inventory system.


and I am new to coding
Well, why not starts by basic coding courses ? There's tons of them online. Choose one that regard Python, it will kill two birds with a single stone.



I can do the rest of the codes looking at tutorials.
Sorry to be harsh, but no, you clearly can't. This for three major reasons:

1) You are totally unable to see that the information you want to display (the quantity for each item), do not exist. This despite the fact that I said in my previous post that it do not exist.

2) You are totally unable to see that I already gave you the full code to display the inventory in a box. The only thing missing being the style turning this into a beautiful box.

3) You were totally unable to find the many inventory system already available here.


There's no shame in not knowing how to code. But when it's the case and you want to do something that will need a lot of coding, the starts is to learn. In no case it is to blindly copy what people, who can be as stupid as the inventory guy, will tell you without understanding what you are doing.
Tutorial exist to help you face an issue that you never encountered. They are not a shortcut to learning.

Your intent is clearly to make a game, but so far I would highly recommend people to not play it, because you'll never be able to fix the bugs they'll find. Not because you are idiot, but because you have no idea what your code is doing, nor how it is doing it. What mean that you'll also have no idea how to fix the bugs.



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

MaxGamez

Newbie
Game Developer
Jan 24, 2023
93
175
Oh god... You really copied the whole code :eek:

This tutorial is either the most stupid way to use a list, or an easy way to looks smart to the eyes of people who know nothing, but in no way this is a tutorial for an inventory system.




Well, why not starts by basic coding courses ? There's tons of them online. Choose one that regard Python, it will kill two birds with a single stone.





Sorry to be harsh, but no, you clearly can't. This for three major reasons:

1) You are totally unable to see that the information you want to display (the quantity for each item), do not exist. This despite the fact that I said in my previous post that it do not exist.

2) You are totally unable to see that I already gave you the full code to display the inventory in a box. The only thing missing being the style turning this into a beautiful box.

3) You were totally unable to find the many inventory system already available here.


There's no shame in not knowing how to code. But when it's the case and you want to do something that will need a lot of coding, the starts is to learn. In no case it is to blindly copy what people, who can be as stupid as the inventory guy, will tell you without understanding what you are doing.
Tutorial exist to help you face an issue that you never encountered. They are not a shortcut to learning.

Your intent is clearly to make a game, but so far I would highly recommend people to not play it, because you'll never be able to fix the bugs they'll find. Not because you are idiot, but because you have no idea what your code is doing, nor how it is doing it. What mean that you'll also have no idea how to fix the bugs.



You don't have permission to view the spoiler content. Log in or register now.
footnote was funny, and yeah without understanding the code, bug fixing will be a luxury. thanks I will look into python tutorials first.