And now here is my shiny fresh second attempt at asking this question, which is basically a Python question - but in relation to Ren'py/Inventories.
So what I have so far is a working Inventory system which uses Objects and Classes. I've cobbled it together using parts from Saguaro's 'Infinite, Stackable Inventory' plus a little of Pippin123's Dynamic Dress Up Framework thrown in for good measure and so far it's doing what I want it to. I have a 'Wardrobe' screen that lists both what my Player(Inventory) is wearing and also what the Wardrobe(Inventory) contains, and if I click on any item in either list it automatically moves it from one inventory to the other ... Just as I intended.
Only issue is, say the player is wearing a t-shirt, and they click on another t-shirt from their wardrobe, it would put TWO shirts on them, when in reality they'd swap from one to the other. Or what if they were wearing pants and a shirt and they wanted to put a dress on - they'd need to take off BOTH things first, right?
Well, I have my solution for this conundrum (in theory) and now I just need to find a way of implementing it in using Python lists ... Which is where YOU come in!
So here's what I have so far in terms of code for my Inventory system:
Code: Select all
init python: import renpy.store as store class Clothing(store.object): def __init__(self,name,desc,place): self.name = name self.desc = desc self.place = place place =  ### <--- I feel like this is going to be important later! class Inventory(store.object): def __init__(self, name): self.name=name self.wearing= def remove(self,clothes): if clothes in self.wearing: self.wearing.remove(clothes) return def wear(self,clothes): self.wearing.append(clothes) return def remove_all(self): list = [item for item in self.wearing] if list!=: for item in list: self.wearing.remove(item) return def trade(seller, buyer, item): seller.remove(item) buyer.wear(item)
Code: Select all
$ pants = Clothing(name="pants", desc="a pair of pants", place=["legs"]) $ tshirt = Clothing(name="shirt", desc="a boring old t-shirt", place=["torso"]) $ dress = Clothing(name="dress", desc="a pretty blue dress", place=["legs","torso"])
At present, i'm using the 'trade' function from the list above to move each item back and forth between the player and wardrobe inventories, but I know I need to make a new, more complex function - let's say it's called clothes_check.
And I know that in theory, it needs to do (roughly) the following things:
1) check the "place" tags of the new item selected
2) compare them to the "place" tags of all items the Player is currently wearing
3) move any items with matching "place" tags to the Wardrobe
4) move the new item onto the Player
Only problem is, I don't know HOW to do this. I only have a really basic beginner's knowledge of Python. I've been reading up on lists and I know that there's a number of functions that might work, ways of comparing two lists, like this StackOverflow question about comparing the common elements in two lists using Python ... But even so, translating that into a working inventory function just seems like one step beyond me!
I mean, I obviously want to figure this out on my own, but I feel like it's a three-week Python learn-at-home course away and I really wanted to get my Inventory system up and running asap! If anyone has any ideas of how to create this function, that would be totally amazing! And in the spirit of trying to figure it out on my own, I'm posting below my totally awful not-working attempt at writing the function myself, just so you can see just how far along (or not) i am in trying to wrap my head around all this!!
Code: Select all
def clothes_check(player, wardrobe, item) player.wear(item) for [place] in player.wear(item): if [place] in player.wearing: wardrobe.wear(item)