[Solved] Show clothes with tag in wardrobe

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
Versial
Newbie
Posts: 2
Joined: Fri Jan 20, 2023 8:40 pm
Contact:

[Solved] Show clothes with tag in wardrobe

#1 Post by Versial »

Here's the code I'm working with:

Code: Select all

init python:
    class ClothingItem:
        def __init__(self, name, tag, image, girly = 0,):
            self.name = name
            self.girly = girly
            self.image = image
            self.tag = tag


        def check_valid_position(self, layer, position):
            if self.layer == layer and self.position == position:
                return True
            else:
                return False
    
    class Wardrobe:
        def __init__(self):
            self.girly_index = 0
            self.wearing = []
            self.wardrobe = []

        def add_clothes(self, clothes):
            if clothes not in self.wardrobe:
                self.wardrobe.append(clothes)
            return
        
        def remove_clothes(self, clothes):
            if clothes in self.wardrobe:
                self.wardrobe.remove(clothes)
            return
        
        def undress(self, clothes):
            if clothes in self.wearing:
                self.wearing.remove(clothes)
                self.girly_index -= clothes.girly
            return
        
        def wear(self, clothes):
            temp = self.wearing[:] # make copy of wearing list
            for item in temp: # iterate over copy of wearing list
                if item.tag == clothes.tag:
                    self.undress(item) # if same slot, then properly remove from wearing list
            self.wearing.append(clothes)
            self.girly_index += clothes.girly
            return
        
        def get_image_wearing(self, tag):
            for item in self.wearing:
                if item.tag == tag:
                    return item.image

        def get_image_all(self, tag):
            for item in self.wardrobe:
                if item.tag == tag:
                    return item.image

        def check_tag(wardrobe, tag):
            # get all clothing items with a certain tag
            clothes_with_tag = []
            for item in wardrobe.wardrobe:
                if item.tag == tag:
                    clothes_with_tag.append(item)
            return clothes_with_tag
I have a wardrobe screen, when you click on the type of item (in this case underwear) it opens a separate screen for that type.

Code: Select all

screen underwear:
    modal True
    imagebutton:
        xpos 10
        ypos 0
        auto "gui/relationship/game_button_variate_%s.png"
        action ToggleScreen ("showstats")

    vbox:
        xalign 0.5
        ypos 0.08
        spacing 10
        frame:
            xsize 1000
            ysize 720
            $ x = 10 # coordinates of the top left item position
            $ y = 10
            
            for i, name in enumerate(wardrobe.check_tag("under bottom")):
                $ x += 320
                $ pic = "clothes/" + wardrobe.get_image_all("under bottom")
                frame:
                    xalign 1.2
                    xpos x
                    ypos y
                    imagebutton:
                        idle pic
                        hover pic
                        action [
                            Show("wardrobe_button"),
                            SetVariable("wardrobe.wear", name),
                            Hide("underwear"),
                            Show("wardrobe")
                        ]

                $ i += 1
Right now, the

Code: Select all

$ pic = "clothes/" + wardrobe.get_image_all("under bottom")
portion returns the first item in the list and repeats it for the number of times in the list. I want all items in the list to be displayed and I'm lost on how to move forward. In this case, all items in the wardrobe with the tag "under bottom".
Last edited by Versial on Fri Jan 27, 2023 10:28 pm, edited 1 time in total.

Versial
Newbie
Posts: 2
Joined: Fri Jan 20, 2023 8:40 pm
Contact:

Re: Show clothes with tag in wardrobe

#2 Post by Versial »

I found a fix, for those interested:

Code: Select all

$ clothes_with_tag = wardrobe.check_tag("under bottom")
            for i, item in enumerate(clothes_with_tag):
                $ x += 320
                $ pic = "clothes/" + clothes_with_tag[i].image

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]