Need help with custom classes (sort of inventory-ish)

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
Gamma Vector
Newbie
Posts: 20
Joined: Thu Feb 25, 2010 9:15 pm
Contact:

Need help with custom classes (sort of inventory-ish)

#1 Post by Gamma Vector » Thu Oct 20, 2016 3:28 am

Okay, so what I'm trying to do is create a system where the player can wear different clothing, and NPCs will notice. Some of them have preferences for what the player wears.

The way I'm trying to do this is to create clothing objects which have "style characteristics" as a property represented by an integer. So, for instance, a dress could have 2 elegance and 5 frilliness. Then, it's added to a list of what the player is wearing, and it's style characteristics are added to a running tally. Finally, the style characteristic tallies are checked against each other to see which one is dominant, and the player's overall style is determined.

So, if the player is wearing a dress which gives 2 elegance and 5 frilliness, but also shoes which give 3 elegance and a hat which gives 1 elegance, their overall style should be "elegant."

This is what I have so far:

Code: Select all

class Clothes:
        def __init__(self, name, description, flashy=0, elegant=0, frilly=0):
            self.name = name
            self.desc = description
            self.flashy = flashy
            self.elegant = elegant
            self.frilly = frilly

    class Wardrobe:
        def __init__(self, name):
            self.name = name
            self.flashy_index = 0
            self.elegant_index = 0
            self.frilly_index = 0
            self.style = ""
            self.wearing=[]
        
        def check_style(self):
            if self.flashy_index > self.elegant_index and self.flashy_index > self.frilly_index :
                self.style = "flashy"
            elif self.elegant_index > self.flashy_index and self.elegant_index > self.frilly_index :
                self.style = "elegant"
            elif self.frilly_index > self.elegant_index and self.frilly_index > self.flashy_index :
                self.style = "frilly"
            else :
                self.style = "eclectic"
            return           
        
        def remove(self, clothes):
            if clothes in self.wearing:
                self.wearing.remove(clothes)
                self.flashy_index -= clothes.flashy
                self.elegant_index -= elegant.flashy
                self.frilly_index -= clothes.frilly
            return
       
        def wear(self, clothes):
            self.wearing.append(clothes)
            self.flashy_index += clothes.flashy
            self.elegant_index += clothes.elegant
            self.frilly_index += clothes.frilly
            return
       
        def remove_all(self):
            list = [item for item in self.wearing]
            if list!=[]:
                for item in list:
                    self.wearing.remove(item)
                self.flashy_index = 0
                self.elegant_index = 0
                self.frilly_index = 0
            return
To me, it looks like it ought to work. However, when I do something like this this:

Code: Select all


$ player = Wardrobe("Player")
$ sundress = Clothes("Sundress", "a simple dress," 0, 0, 5)
$ player.wear(sundress)
$ style = player.check_style
"Your style is [style]."

It doesn't work. I get "Your style is <bound method Wardrobe.check_style of <store.Wardrobe instance at 0x0473AE68>>"

Does anybody know what I'm doing wrong, and what I might do to fix it?
(Ideally, I'd also like to know how to display a list of what the player is wearing. Right now, when I try to do that by assigning player.wearing to a variable and printing the variable, I get [<store.Clothes instance at 0x04761738>])

EDIT: Accidentally left out a section of code. Have fixed it.

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Need help with custom classes (sort of inventory-ish)

#2 Post by Ocelot » Thu Oct 20, 2016 5:23 am

You need to call method to get result:

$ style = player.check_style()
< < insert Rick Cook quote here > >

Gamma Vector
Newbie
Posts: 20
Joined: Thu Feb 25, 2010 9:15 pm
Contact:

Re: Need help with custom classes (sort of inventory-ish)

#3 Post by Gamma Vector » Thu Oct 20, 2016 5:25 am

Ocelot wrote:You need to call method to get result:

$ style = player.check_style()
Well, I feel hilariously stupid. Thank you so much for your help!

Post Reply

Who is online

Users browsing this forum: No registered users