- Mar 9, 2020
- 147
- 273
Hi! Some of you might know me from my HTML/Twine game Girl Games! Well, I'm currently trying to port it across to Ren'py and it was all going great until i start trying to replicate some of the more advanced features!
The main snag I've hit upon is in my wardrobe/inventory. I've managed to get a working Inventory system going which uses Objects and Classes. I've cobbled it together using parts from a couple of inventories on the LemmaSoft forums, namely this
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 had a solution for this in my Twine game, which was code that was kindly written for me by Hiev over on the TFGames forum, and now I'm trying to write something similar in Python. Only issue is, my python coding skills are totally not up to scratch!!
The way the orignal verson worked, I would add in a 'place' tag to each item in my inventory - so for pants it would be place = ["legs"], shirt woud be place = ["torso"] and dress would be place = ["legs", "torso"] .. I know that I can do the same thing in Python with lists. And in theory work up some way of cycling through to check if each new item the player wanted to wear already had that tag in anything they were currently wearing and if so send it from the player back to the wardrobe.
Maybe it's a little clearer if I share the code i have currently. This is for my Ren'py version:
And I'm creating each of my clothing items like so:
As you can see, in the Clothing objects I'm adding in a "place" list, which specifies which place on the body the item is to be worn. Which means that in theory, if my player was wearing pants and a shirt and they put on a dress - I could use Python to make sure that any items the player was currently wearing with those matching tags got sent to the wardrobe!
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
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!
The closest I've got on my own is this total trainwreck:
which obviously doesn't work! So yeah, if anyone has any ideas or solutions that would be awesome! Thank you in advance.
p.s. I have also posted a similarly-worded version of this question over on the LemmaSoft forum too. If it gets answered there, I'll make sure to update this post with the solution, just in case anyone ever runs into the same issue in the future!
The main snag I've hit upon is in my wardrobe/inventory. I've managed to get a working Inventory system going which uses Objects and Classes. I've cobbled it together using parts from a couple of inventories on the LemmaSoft forums, namely this
You must be registered to see the links
and this
You must be registered to see the links
... well, 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 had a solution for this in my Twine game, which was code that was kindly written for me by Hiev over on the TFGames forum, and now I'm trying to write something similar in Python. Only issue is, my python coding skills are totally not up to scratch!!
The way the orignal verson worked, I would add in a 'place' tag to each item in my inventory - so for pants it would be place = ["legs"], shirt woud be place = ["torso"] and dress would be place = ["legs", "torso"] .. I know that I can do the same thing in Python with lists. And in theory work up some way of cycling through to check if each new item the player wanted to wear already had that tag in anything they were currently wearing and if so send it from the player back to the wardrobe.
Maybe it's a little clearer if I share the code i have currently. This is for my Ren'py version:
Python:
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)
Python:
$ 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
You must be registered to see the links
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!
The closest I've got on my own is this total trainwreck:
Python:
def clothes_check(player, wardrobe, item)
player.wear(item)
for [place] in player.wear(item):
if [place] in player.wearing:
wardrobe.wear(item)
p.s. I have also posted a similarly-worded version of this question over on the LemmaSoft forum too. If it gets answered there, I'll make sure to update this post with the solution, just in case anyone ever runs into the same issue in the future!