Ren'Py Help with creating a wardrobe/skins system?

Ikatikei

Newbie
Aug 1, 2018
91
47
I've been trying to create a skin/wardrobe system for a project that I am working on, but I found some problems with it.
Here is my code:

Python:
init python:
    class Skin(object):
        def __init__(self, char, name, unlocked):
            self.char = char                          
            self.name = name
            self.unlocked = unlocked

        @property
        def ButtonImage(self):
            Output = "images/ui/newward/" + self.char + "_" + self.name + ".png"        #### This is for the skin sprite that will show in the wardrobe.
            return Output

        @property
        def ButtonHover(self):
            Output = "images/ui/newward/" + self.char + "_" + self.name + "h.png"   #### This is for the skin sprite that will show in the wardrobe when the mouse arrow is over the button.
            return Output

        def UnlockSkin(self):
            if unlocked == False:        ## I created this method after a little searching but didn't find the proper way to use it or even if it's coded right.
                return True


skins = []
    skins.append(Skin("kelly","outfit1", True))
    skins.append(Skin("kelly","outfit2", True))
Python:
default kelly_skin = ""                                ### I use it to change the skin in the sprite.

image kelly = "images/kelly/body_[kelly_skin].png"
Here is the wardrobe screen code:

Python:
screen ward():
    modal True
    add "images/ui/wardrobe/bgward.png"
  
    vbox:
        grid 5 1:
            allow_underfull True
            xpos 700
            ypos 120
            spacing 20
            for q in skins:
                if q.unlocked:
                    hbox:
                        imagebutton:
                            idle q.ButtonImage #( "images/ui/wardrobe/{}.png".format( skins[i] ) )
                            hover q.ButtonHover  #( "images/ui/wardrobe/{}h.png".format( skins[i] ) )
                            focus_mask True
                            action SetVariable("kelly_skin", q.name)


textbutton "X" text_style "base":
        xpos 1215
        ypos 95

         action Hide("ward"), Call("kelly_actions")                                   ##This button hides the wardrobe screen and returns to the character actions menu.
So...When the code is like that, it works fine. My real problem here, is when I try to add the skins from a label. Example:

Python:
label mission1:
    "This is the mission 1."
    "Here is a new outfit for you."
    $ skins.append(Skin("kelly","outfit2", True))       
    return
The skin is unlocked and the button in wardrobe is created, but just along the game is not closed or reloaded. I don't know exactly what I am doing wrong, so your help would be appreciated.


ps. I'd also like to add empty slots for the wardrobe screen. For example, if the skin is locked it will show a slot with a lock inside. And even if there's no skin, it will show the empty slot image.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,979
16,236
The skin is unlocked and the button in wardrobe is created, but just along the game is not closed or reloaded. I don't know exactly what I am doing wrong, so your help would be appreciated.
What you're doing wrong is not reading the documentation in order to know how to use Ren'Py:

" "

If you just declare your variable correctly with , your code should then works as you expect it.
Python:
default skins = [ Skin("kelly","outfit1", True), Skin("kelly","outfit2", True) ]

ps. I'd also like to add empty slots for the wardrobe screen. For example, if the skin is locked it will show a slot with a lock inside. And even if there's no skin, it will show the empty slot image.
*sigh*

Python:
default skins = [ Skin("kelly","outfit1", False) , Skin("kelly","outfit2", False) ]

[...]

screen ward():

           for q in skins:
                if q.unlocked:
                    hbox:
                        [...]
                else:
                    [whatever you want]
 

Ikatikei

Newbie
Aug 1, 2018
91
47
What you're doing wrong is not reading the documentation in order to know how to use Ren'Py:

" "

If you just declare your variable correctly with , your code should then works as you expect it.
Python:
default skins = [ Skin("kelly","outfit1", True), Skin("kelly","outfit2", True) ]



*sigh*

Python:
default skins = [ Skin("kelly","outfit1", False) , Skin("kelly","outfit2", False) ]

[...]

screen ward():

           for q in skins:
                if q.unlocked:
                    hbox:
                        [...]
                else:
                    [whatever you want]
Wow. I didn't know that it was so easy to solve. Thanks for your help.