Page 1 of 1

How do I lock and unlock Drees Up items in a list? [HELP]

Posted: Fri Jan 01, 2021 2:56 am
by beastcarving
Here's what I've tried.

Code: Select all

default persistent.dDress = { "skin" : 1, "glasses" : 1, "dress" : 4, "hair" : 2 }
init python:
    def draw_girl(st, at):
        return LiveComposite(
            (0, 0),
            (0, 0), im.FactorScale('base.png', 1.5, 1.5),
            (0, 0), im.FactorScale( 'skin{}.png'.format(persistent.dDress['skin']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'dress{}.png'.format(persistent.dDress['dress']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'hair{}.png'.format(persistent.dDress['hair']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'glasses{}.png'.format(persistent.dDress['glasses']), 1.5, 1.5 )
            ), .1

image girl = DynamicDisplayable(draw_girl)   

init python:
    class DressUp(Action):
        def __init__(self, dict, key, value, max):
            self.dict = dict
            self.key = key
            self.value = value
            self.max = max

        def __call__(self):
            value = self.dict[self.key] + self.value
            if value < 1:
                value = self.max
            elif value > self.max:
                value = 1

            self.dict[self.key] = value
            renpy.restart_interaction()
Here's what I've added to this code:

Code: Select all

init python:
    def draw_girl(st, at):
        return LiveComposite(
            (0, 0),
            (0, 0), im.FactorScale('base.png', 1.5, 1.5),
            (0, 0), im.FactorScale( 'skin{}.png'.format(persistent.dDress['skin']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'dress{}.png'.format(persistent.dDress['dress']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'hair{}.png'.format(persistent.dDress['hair']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'glasses{}.png'.format(persistent.dDress['glasses']), 1.5, 1.5 )
            ), .1
            #The line below is the one I add. I thought this would work, but I got lost somewhere. Can someone help me fix this please?
            if persistent.promdress == "unlockpromdress":
                (0, 0), im.FactorScale( 'promdress.png'.format(persistent.dDress['dress']), 1.5, 1.5 )
                

Re: How do I lock and unlock Drees Up items in a list? [HELP]

Posted: Fri Jan 01, 2021 6:07 am
by emanuel
It seems you're not really understanding this code, so I added some explanation.

This line sets a dictionary that is referenced to pick the right images, so for example, without change, dress4.png will be used.

Code: Select all

default persistent.dDress = { "skin" : 1, "glasses" : 1, "dress" : 4, "hair" : 2 }
Here a function is defined. This is called when the girl needs to be drawn

Code: Select all

init python:
    def draw_girl(st, at):
The next lines are actually one statement; the only statement in this function. It is split over multiple lines for readability. This returns a value in the form of LiveComposite and a float. I don't actually know what LiveComposite is, but it's something that evaluates to a displayable (a subclass I presume). Notice the opening parentheses on the first line

Code: Select all

        return LiveComposite(
            (0, 0),
            (0, 0), im.FactorScale('base.png', 1.5, 1.5),
            (0, 0), im.FactorScale( 'skin{}.png'.format(persistent.dDress['skin']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'dress{}.png'.format(persistent.dDress['dress']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'hair{}.png'.format(persistent.dDress['hair']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'glasses{}.png'.format(persistent.dDress['glasses']), 1.5, 1.5 )
            ), .1
And in the line above we have the matching closing parentheses. This ends the argument list for LiveComposite. Followed by a float. At this point the function returns and any code below in this function (what you've addded) will never be executed. Even if you would add to this list of arguments, you will get a composite image containing both the dress and your prom dress, which is not what you want (I assume). You'd want the entry for the dress to change, not add one.

This defines a specific kind of image; a dynamic one. The function defined above is passed as an argument, causing that to be called repeatedly when drawn.
The functions first return value (the LiveComposite) sets the image, and the second (the float) the time it takes before the function is called again (.1 seconds in this case)

Code: Select all

image girl = DynamicDisplayable(draw_girl)

This defines a class of callable objects. Each time such an object is called, it changes the entry in the dictionary above, to change what the girl is wearing.
We don't actually see how or when this is used in this snippet of code, but I assume it's either to switch outfits or to show a series of images of the girl getting dressed.

Code: Select all

    class DressUp(Action):
The value argument in its constructor is what's added each time the object is called; wrapping around at max. For example: an instance constructed with (persistent.dDress, glasses, 1, 2) will switch between using glasses1.png and glasses2.png every time it's called. With value and max being 2 and 5, respectively, it would go from glasses1 to glasses3 to glasses5 and then start back at 1.

Code: Select all

        def __init__(self, dict, key, value, max):
            self.dict = dict
            self.key = key
            self.value = value
            self.max = max
This the code that actually sets the value in the dictionary when an object of type DressUp is called

Code: Select all

        def __call__(self):
            value = self.dict[self.key] + self.value
            if value < 1:
                value = self.max
            elif value > self.max:
                value = 1

            self.dict[self.key] = value
            renpy.restart_interaction()
I hope that explains enough for you to be able to change what you want to change. I assume the 'promdress' is already part of the game, and you just want to unlock it. If that's the case, then I've got bad news for you. The game doesn't use the code above for parts that involve the 'promdress'. There is no way the above code will result in 'promdress.png' so it uses different logic for that; presumably not composite images but only a limited set of prerendered scenes. Happy new year.

Re: How do I lock and unlock Drees Up items in a list? [HELP]

Posted: Sat Jan 02, 2021 6:47 am
by beastcarving
So there is no way I can add new unlockable items to this code?

Re: How do I lock and unlock Drees Up items in a list? [HELP]

Posted: Thu Jan 07, 2021 9:10 pm
by beastcarving
:D :D I do understand the code a bit better after reading your examples, and was able to take things a bit further. Thanks!

Code: Select all

init python:
    def draw_girl(st, at):
        return LiveComposite(
            (0, 0),
            (0, 0), im.FactorScale('base.png', 1.5, 1.5),
            (0, 0), im.FactorScale( 'skin{}.png'.format(persistent.dDress['skin']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'dress{}.png'.format(persistent.dDress['dress']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'hair{}.png'.format(persistent.dDress['hair']), 1.5, 1.5 ),
            (0, 0), im.FactorScale( 'glasses{}.png'.format(persistent.dDress['glasses']), 1.5, 1.5 )
                         if persistent.promdress == "unlockpromdress":
                (0, 0), im.FactorScale( 'dress6.png'.format(persistent.dDress['dress']), 1.5, 1.5 )
            ), .1
                
8) I went ahead and made dress 6 the unlockable dress. What it should do is, unlock this dress from the list of dress if 'unlockpromdress equal True.' However in place of the dress, I needed to show an image 'if dress6 equal False' because this code is set to look for 6 dresses now, and if it can't... there will be an error.
:idea: So, I went ahead and made two versions of dress 6.
ex.

Code: Select all

  
                         if persistent.promdress == "unlockpromdress":
                (0, 0), im.FactorScale( 'dress6.png'.format(persistent.dDress['dress']), 1.5, 1.5 )
                           else persistent.promdress == "nopromdress":
                (0, 0), im.FactorScale( 'dress6.png'.format(persistent.dDress['dress']), 1.5, 1.5 )
                              
                
:D This other image (dress6.png) will appear as a plain grey dress with a question mark over it, until it is replaced with this the other dress6.png (the promdress.)

:cry: I thought I had this one figured out, until I noticed that, two file with the same name can NOT exist in the same folder with out one overwriting the other.

I reallyyyyyy need some help with this. Maybe someone else knows a simpler solution that I'm over-looking. :?

Re: How do I lock and unlock Drees Up items in a list? [HELP]

Posted: Fri Jan 15, 2021 7:53 pm
by beastcarving
Bump hello bump