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

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
User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

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

#1 Post by beastcarving » Fri Jan 01, 2021 2:56 am

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 )
                
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

emanuel
Newbie
Posts: 12
Joined: Fri Dec 25, 2020 8:44 am
Contact:

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

#2 Post by emanuel » Fri Jan 01, 2021 6:07 am

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.

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

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

#3 Post by beastcarving » Sat Jan 02, 2021 6:47 am

So there is no way I can add new unlockable items to this code?
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

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

#4 Post by beastcarving » Thu Jan 07, 2021 9:10 pm

: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. :?
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

User avatar
beastcarving
Regular
Posts: 139
Joined: Mon May 13, 2019 5:03 pm
Completed: Pulse Cage https://beastcarving.itch.io/pulse-cage-the-full-series
Projects: Your Brother's Religion
Organization: BeastCarving Studio
IRC Nick: BeastCarving
Tumblr: beastcarving
Deviantart: beastcarving
Github: beastcarving
itch: beastcarving
Contact:

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

#5 Post by beastcarving » Fri Jan 15, 2021 7:53 pm

Bump hello bump
Image Pulse Cage (full game)Image Your Brother's Religion (Demo)
PLAY HERE: https://beastcarving.itch.io/
Love my work: https://www.patreon.com/beastcarving

Post Reply

Who is online

Users browsing this forum: No registered users