Issue with returning item count and displaying only unique values in a list

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
McRad
Regular
Posts: 28
Joined: Wed Oct 14, 2015 5:52 pm
Projects: Eastbound Stars: The Drowning Halls
Contact:

Issue with returning item count and displaying only unique values in a list

#1 Post by McRad »

Hello everybody, I am currently working on my inventory system for the RPG I am developing. I am running into a small issue concerning renpy's handling of python code, as I want to incorporate a FF style display with text and item count as seen below.
Image

I have been working over the past few days to see if I can fix this issue. The farthest I was able to get was to put code inside of the screen that the player uses to access items.

Code: Select all

	for items in armory.inventory:
            $ simparm = set(armory.inventory)
        for items in armory.inventory:
            $ numcheck = armory.inventory.count(items)
        for items in simparm:
            textbutton "[items.name] X[numcheck]" action SetVariable ("itemselect", items)
The code is able to correctly display all unique items with no duplicates (Duplicates meaning that the screen displays the same item twice as textbuttons not two items existing in the list). However the item count for each item is wrong. numcheck will only update itself to the amount of occurrences of the newest item added to the list.

I have tried doing list(set(armory.inventory)), but it does the exact same thing.

I am able to have numcheck work as intended but I would have to change the code to

Code: Select all

         for items in armory.inventory:
	    $ numcheck = armory.inventory.count(items)
	    textbutton "[items.name] X[numcheck]" action SetVariable ("itemselect", items)


Otherwise I am at a loss on how to implement this feature correctly. At this point I am certain that I may need to change up the inventory system I have in place, but I do want to note that I am looking to keep items listed as textbuttons and have their amount listed on screen.

I can provide more code from the inventory code. However I don't think that any other piece of code is conflicting aside from the code listed here.

Any help is appreciated

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Issue with returning item count and displaying only unique values in a list

#2 Post by philat »

Pretty sure just using a dictionary would make this much simpler.

McRad
Regular
Posts: 28
Joined: Wed Oct 14, 2015 5:52 pm
Projects: Eastbound Stars: The Drowning Halls
Contact:

Re: Issue with returning item count and displaying only unique values in a list

#3 Post by McRad »

philat wrote: Mon Aug 05, 2019 9:05 pm Pretty sure just using a dictionary would make this much simpler.
I should explain that the items stored in here are instances of class values and I wouldn't believe that a dictionary could be compatible with that

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Issue with returning item count and displaying only unique values in a list

#4 Post by philat »

No reason that should be the case.

McRad
Regular
Posts: 28
Joined: Wed Oct 14, 2015 5:52 pm
Projects: Eastbound Stars: The Drowning Halls
Contact:

Re: Issue with returning item count and displaying only unique values in a list

#5 Post by McRad »

philat wrote: Tue Aug 06, 2019 1:31 am No reason that should be the case.
I was thinking it over and maybe it could work... but I am very unsure of how I could get it to display all the unique data that I want it too...

I want it in individual textbuttons you can click on to use or equip, I'm unsure of how storage works in dictionaries anyways. Can I call each unique one with like [1] and it gets the key and value?

McRad
Regular
Posts: 28
Joined: Wed Oct 14, 2015 5:52 pm
Projects: Eastbound Stars: The Drowning Halls
Contact:

Re: Issue with returning item count and displaying only unique values in a list

#6 Post by McRad »

McRad wrote: Tue Aug 06, 2019 1:45 am
I was thinking it over and maybe it could work... but I am very unsure of how I could get it to display all the unique data that I want it too...

I want it in individual textbuttons you can click on to use or equip, I'm unsure of how storage works in dictionaries anyways. Can I call each unique one with like [1] and it gets the key and value?
I tried doing it and it seemed to be unable to work at all. Anybody else have any other suggestions?

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Issue with returning item count and displaying only unique values in a list

#7 Post by philat »

I mean, there are too many ways to do what you want to do. You could do it with dictionaries, you could do it with lists of tuples, you could put a separate attribute for each item class to indicate the number of items held. Heck, if you wanted to, you could count the number of duplicates in a list like you were trying to originally, although I don't see why you would. Try looking around the forums for inventory examples. viewtopic.php?f=51&t=34131

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Issue with returning item count and displaying only unique values in a list

#8 Post by Kia »

I think your use of classes and screens is a bit wrong, instead of trying to use python lines inside a screen, move all of your python code into the classes and have them calculate and handle the variables for you.

the code to show the number of an item should be like:

Code: Select all

text str(inv.numcheck(wood))
anywhere you found yourself typing $ inside a screen, you should tell yourself: there's a better way yo do this

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]