Dress Up / DynamicDisplayable Saving Problem

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
screamingpenguin
Regular
Posts: 32
Joined: Mon Dec 11, 2017 5:11 am
Projects: Hollow Voices
Contact:

Dress Up / DynamicDisplayable Saving Problem

#1 Post by screamingpenguin »

Hello!
Recently I've found this amazing piece of coding viewtopic.php?f=51&t=30643#p358786 which I ended up adopting as it was perfect for what I'm trying to achieve. So far, everything works perfectly!
Except for two really big issues...

#1 - Saving does not work
After creating the character sprite, if I were to save and exit the game, and then reopen the game and load that file, the sprite is reset back to defaults. I have a hunch why this is, but I can't figure out how to do anything about it, I am not highly experienced with coding hence why I'm here. I've spent the last two entire days just glued to my computer trying to figure this out and I'm no closer to finding a solution.
I suspect it's due to the init python and the def PCstats parts, but I have absolutely no idea how to go about modifying it to prevent loading those settings upon every startup. I have posted the entire script code at the bottom of this post for reference.

#2 - Saving, Loading different file, overrides sprite
On a similar train to the above problem, if I were to save after creating the character sprite, and then go to load a different save file, that save file's sprite is automatically changed to the sprite I JUST made in the new file. This problem isn't as important as the one above, but still quite annoying. Again, the code is posted below if anyone more experienced than I can identify the issues that cause these..

I will be eternally grateful for any and all assistance, thank you ! 🙏

Code: Select all

init python:
    import renpy.store as store
    import renpy.exports as renpy
    from operator import attrgetter

    class PCstats(renpy.store.object):
        def __init__(self, name):
            self.name=name
            self.backhair="1"
            self.backhaircolor="white"
            self.bangs="1"
            self.bangscolor="white"
            self.eyecolor="blue"
            self.eyeshadowcolor="null"
            self.glasses="null"
            self.skin="1"
            self.nose="1"
            self.lipstick="null"
            self.wearing=[]

        def remove(self,clothes):
            if clothes in self.wearing:
                self.wearing.remove(clothes)
            return

        def wear(self,clothes):
            self.wearing.append(clothes)
            return

        def remove_all(self):
            list = [item for item in self.wearing if item.can_strip]
            if list!=[]:
                for item in list:
                    self.wearing.remove(item)
            return

    class clothing(renpy.store.object):
        def __init__(self, name,pic,priority=10,can_strip=True):
            self.name=name
            self.pic=pic
            self.priority=priority
            self.can_strip=can_strip

    def draw_clothing(st,at,character,art_path="MC_Female/",mouth="normal",eyes="normal",blushing=""):
        list=sorted(character.wearing, key=attrgetter('priority')) # Each item as a priority so we don't draw the blouse over the vest, etc
        startpic= art_path+"Hair/backhair_"+character.backhair+"_"+character.backhaircolor+".png"
        command_line="LiveComposite((579,971),(0,0),\""+startpic+"\""
        command_line=command_line+",(0,0),\""+art_path+"skin_"+character.skin+".png\""
        command_line=command_line+",(0,0),\""+art_path+"nose_"+character.nose+".png\""
        command_line=command_line+",(0,0),\""+art_path+"Eyes/eyeshadow_"+eyes+"_"+character.eyeshadowcolor+".png\""
        command_line=command_line+",(0,0),\""+art_path+"Eyes/eyes_"+eyes+"_"+character.eyecolor+".png\""
        command_line=command_line+",(0,0),\""+art_path+"Accessories/glasses_"+character.glasses+".png\""
        command_line=command_line+",(0,0),\""+art_path+"Lipstick/mouth_"+mouth+"_"+character.lipstick+".png\""

        if blushing<>"":
            command_line=command_line+",(0,0),\""+art_path+"_blushing_"+blushing+".png\""
        command_line=command_line+",(0,0),\""+art_path+"Hair/bangs_"+character.bangs+"_"+character.bangscolor+".png\""

        # Then we draw each item the char is wearing.
        for item in list:
            command_line=command_line+",(0,0),\""+art_path+item.pic+"\""
        command_line=command_line+")"

        return eval(command_line),None

################################################################################
## Define Clothing
################################################################################


########## STOCKINGS     ( LAYER 2 ) ##########
########## PANTS         ( LAYER 3 ) ##########
########## TOPS          ( LAYER 4 ) ##########
    # etc tops
    mcf_top001=clothing("Purple Floral Top", "Clothes/top1.png",4,True)
    mcf_top002=clothing("Lace Top", "Clothes/lace_shirt.png",4,True)
    # tanks
    mcf_tanktop001=clothing("Black Tank Top", "Clothes/tank_top.png",4,True)
    # tees
    mcf_tshirt001=clothing("Green Tee", "Clothes/tshirt1.png",4,True)
    mcf_tshirt002=clothing("Blue Tee", "Clothes/tshirt2.png",4,True)
    mcf_tshirt003=clothing("Purple Tee", "Clothes/tshirt3.png",4,True)
    mcf_tshirt004=clothing("Pink Tee", "Clothes/tshirt4.png",4,True)
    mcf_tshirt005=clothing("Red Tee", "Clothes/tshirt5.png",4,True)
    mcf_tshirt006=clothing("Camo Tee", "Clothes/tshirt6.png",4,True)
    mcf_tshirt_chemistry=clothing("Chemistry Pun Tee", "Clothes/tshirt_chemistry.png",4,True)
########## COATS         ( LAYER 5 ) ##########
########## ACCESSORIES   ( LAYER 6 ) ##########

################################################################################
## Wardrobe Inventory
################################################################################
default wardrobe_stockings = [""]
default wardrobe_pants = [""]
default wardrobe_tops = ["",mcf_top001,mcf_top002,mcf_tanktop001,mcf_tshirt001,mcf_tshirt002,mcf_tshirt003]
default wardrobe_coats = [""]
default wardrobe_accessories = [""]
################################################################################
## Defining Player Sprites
################################################################################
init:
    # Female
    $ mcf = PCstats("mcf")
    image mc normal = DynamicDisplayable(draw_clothing,character=mcf,art_path="MC_Female/",mouth="normal",eyes="normal")
    image mc sad = DynamicDisplayable(draw_clothing,character=mcf,art_path="MC_Female/",mouth="frown",eyes="sad")
    image mc worried = DynamicDisplayable(draw_clothing,character=mcf,art_path="MC_Female/",mouth="worried",eyes="normal")
    image mc grit = DynamicDisplayable(draw_clothing,character=mcf,art_path="MC_Female/",mouth="grit",eyes="sad")
    image side mc = LiveCrop((74,83,394,394), "mc normal")
    define mc = Character("[name]",image="mc")

label start:
    scene black
    menu: 
        "Are you male or female?"
        "Male":
            $ gendermale = True
            $ genderfemale = False
            $ gender = "male"
            $ he_or_she = "he"
            $ he_or_she_caps = "He"
            $ him_or_her = "him"
            $ his_or_her = "his"
            $ hes_or_shes = "he's"
            $ suff = "kun"
        "Female":
            $ gendermale = False
            $ genderfemale = False
            $ gender = "female"
            $ he_or_she = "she"
            $ he_or_she_caps = "She"
            $ him_or_her = "her"
            $ his_or_her = "her"
            $ hes_or_shes = "she's"
            $ suff = "chan"
    python:
        name = renpy.input("What is your name?")
        name = name.strip()
    show mc normal
    "{i}Create your character."
    show mc at left with ease:
    "{i}What should we change?"
    label create_character:
    hide window
    menu:
        "Skin Colour":
            menu skincolor_select:
                "Tone 1":
                    $ mcf.skin="1"
                    jump skincolor_select
                "Tone 2":
                    $ mcf.skin="2"
                    jump skincolor_select
                "Tone 3":
                    $ mcf.skin="3"
                    jump skincolor_select
                "Tone 4":
                    $ mcf.skin="4"
                    jump skincolor_select
                "{b}Done":
                    jump create_character
        "Hair":
            menu modify_hair:
                "Change Hairstyle":
                    menu select_hairstyle:
                        "Bangs":
                            menu select_hairstyle_bangs:
                                "Style 1":
                                    $ mcf.bangs="1"
                                    jump select_hairstyle_bangs
                                "Style 2":
                                    $ mcf.bangs="2"
                                    jump select_hairstyle_bangs
                                "{b}Done":
                                    jump select_hairstyle
                        "Back Hair":
                            menu select_hairstyle_back:
                                "Style 1":
                                    $ mcf.backhair="1"
                                    jump select_hairstyle_back
                                "Style 2":
                                    $ mcf.backhair="2"
                                    jump select_hairstyle_back
                                "{b}Done":
                                    jump select_hairstyle
                        "{b}Done":
                            jump modify_hair
                "Change Hair Colour":
                    menu select_haircolor:
                        "Bangs Colour":
                            menu select_haircolor_bangs:
                                "Black":
                                    $ mcf.bangscolor="black"
                                    jump select_haircolor_bangs
                                "Blonde":
                                    $ mcf.bangscolor="blonde"
                                    jump select_haircolor_bangs
                                "Blue":
                                    $ mcf.bangscolor="blue"
                                    jump select_haircolor_bangs
                                "Brown":
                                    $ mcf.bangscolor="brown"
                                    jump select_haircolor_bangs
                                "Green":
                                    $ mcf.bangscolor="green"
                                    jump select_haircolor_bangs
                                "{alpha=0.4}{i}( Next Page )":
                                    menu select_haircolor_bangs2:
                                        "Pink":
                                            $ mcf.bangscolor="pink"
                                            jump select_haircolor_bangs2
                                        "Purple":
                                            $ mcf.bangscolor="purple"
                                            jump select_haircolor_bangs2
                                        "Red":
                                            $ mcf.bangscolor="red"
                                            jump select_haircolor_bangs2
                                        "Teal":
                                            $ mcf.bangscolor="teal"
                                            jump select_haircolor_bangs2
                                        "White":
                                            $ mcf.bangscolor="white"
                                            jump select_haircolor_bangs2
                                        "{alpha=0.4}{i}( Next Page )":
                                            jump select_haircolor_bangs
                                        "{b}Done":
                                            jump select_haircolor
                                "{b}Done":
                                    jump select_haircolor
                        "Back Hair Colour":
                            menu select_haircolor_backhair:
                                "Black":
                                    $ mcf.backhaircolor="black"
                                    jump select_haircolor_backhair
                                "Blonde":
                                    $ mcf.backhaircolor="blonde"
                                    jump select_haircolor_backhair
                                "Blue":
                                    $ mcf.backhaircolor="blue"
                                    jump select_haircolor_backhair
                                "Brown":
                                    $ mcf.backhaircolor="brown"
                                    jump select_haircolor_backhair
                                "Green":
                                    $ mcf.backhaircolor="green"
                                    jump select_haircolor_backhair
                                "{alpha=0.4}{i}( Next Page )":
                                        menu select_haircolor_backhair2:
                                            "Pink":
                                                $ mcf.backhaircolor="pink"
                                                jump select_haircolor_backhair2
                                            "Purple":
                                                $ mcf.backhaircolor="purple"
                                                jump select_haircolor_backhair2
                                            "Red":
                                                $ mcf.backhaircolor="red"
                                                jump select_haircolor_backhair2
                                            "Teal":
                                                $ mcf.backhaircolor="teal"
                                                jump select_haircolor_backhair2
                                            "White":
                                                $ mcf.backhaircolor="white"
                                                jump select_haircolor_backhair2
                                            "{alpha=0.4}{i}( Next Page )":
                                                jump select_haircolor_backhair
                                            "{b}Done":
                                                jump select_haircolor
                                "{b}Done":
                                    jump select_haircolor
                        "{b}Done":
                            jump create_character
                "{b}Done":
                    jump create_character
        "Eyes":
            menu eyecolor_select:
                "Black":
                    $ mcf.eyecolor="black"
                    jump eyecolor_select
                "Blue":
                    $ mcf.eyecolor="blue"
                    jump eyecolor_select
                "Brown":
                    $ mcf.eyecolor="brown"
                    jump eyecolor_select
                "Green":
                    $ mcf.eyecolor="green"
                    jump eyecolor_select
                "Red":
                    $ mcf.eyecolor="red"
                    jump eyecolor_select
                "Teal":
                    $ mcf.eyecolor="teal"
                    jump eyecolor_select
                "Yellow":
                    $ mcf.eyecolor="yellow"
                    jump eyecolor_select
                "{b}Done":
                    jump create_character
        "Makeup":
            menu makeup_select:
                "Eye Shadow":
                    menu eyeshadow_select:
                        "None":
                            $ mcf.eyeshadowcolor="null"
                            jump eyeshadow_select
                        "Black":
                            $ mcf.eyeshadowcolor="black"
                            jump eyeshadow_select
                        "Dark Blue":
                            $ mcf.eyeshadowcolor="darkblue"
                            jump eyeshadow_select
                        "Emerald":
                            $ mcf.eyeshadowcolor="emerald"
                            jump eyeshadow_select
                        "Fuschia":
                            $ mcf.eyeshadowcolor="fuschia"
                            jump eyeshadow_select
                        "{alpha=0.4}{i}( Next Page )":
                            menu eyeshadow_select2:
                                "Green":
                                    $ mcf.eyeshadowcolor="green"
                                    jump eyeshadow_select2
                                "Light Blue":
                                    $ mcf.eyeshadowcolor="lightblue"
                                    jump eyeshadow_select2
                                "Orange":
                                    $ mcf.eyeshadowcolor="orange"
                                    jump eyeshadow_select2
                                "Pink":
                                    $ mcf.eyeshadowcolor="pink"
                                    jump eyeshadow_select2
                                "Purple":
                                    $ mcf.eyeshadowcolor="purple"
                                    jump eyeshadow_select2
                                "{alpha=0.4}{i}( Next Page )":
                                    menu eyeshadow_select3:
                                        "Red":
                                            $ mcf.eyeshadowcolor="red"
                                            jump eyeshadow_select3
                                        "Sandy":
                                            $ mcf.eyeshadowcolor="sandy"
                                            jump eyeshadow_select3
                                        "Teal":
                                            $ mcf.eyeshadowcolor="teal"
                                            jump eyeshadow_select3
                                        "Yellow":
                                            $ mcf.eyeshadowcolor="yellow"
                                            jump eyeshadow_select3
                                        "{alpha=0.4}{i}( Next Page )":
                                            jump eyeshadow_select
                                        "{b}Done":
                                            jump makeup_select
                                "{b}Done":
                                    jump makeup_select
                        "{b}Done":
                            jump makeup_select
                "Lipstick":
                    menu choose_lipstick:
                        "Blue":
                            $ mcf.lipstick="blue"
                            jump choose_lipstick
                        "Green":
                            $ mcf.lipstick="green"
                            jump choose_lipstick
                        "Purple":
                            $ mcf.lipstick="purple"
                            jump choose_lipstick
                        "Red":
                            $ mcf.lipstick="red"
                            jump choose_lipstick
                        "{b}Done":
                            jump makeup_select
                "{b}Done":
                    jump create_character
        "Glasses":
            menu glasses_select:    
                "None":
                    $ mcf.glasses="null"
                    jump glasses_select
                "Large Black":
                    $ mcf.glasses="1"
                    jump glasses_select
                "{b}Done":
                    jump create_character
        "{alpha=0.4}{i}Randomize All":
            $ mcf.backhair=renpy.random.choice(["1"])
            $ mcf.backhaircolor=renpy.random.choice(["black","blonde","blue","brown","green","pink","purple","red","teal","white"])
            $ mcf.bangs=renpy.random.choice(["1","2"])
            $ mcf.bangscolor=renpy.random.choice(["black","blonde","blue","brown","green","pink","purple","red","teal","white"])
            $ mcf.eyecolor=renpy.random.choice(["black","brown","blue","green","red","teal","yellow"])
            $ mcf.eyeshadowcolor=renpy.random.choice(["null","black","lightblue","darkblue","emerald","fuschia","green","orange","pink","purple","red","sandy","teal","yellow"])
            $ mcf.lipstick=renpy.random.choice(["null","blue","green","purple","red"])
            $ mcf.skin=renpy.random.choice(["1","2","3","4"])
            $ mcf.nose=renpy.random.choice(["1","2","3"])
            $ mcf.glasses=renpy.random.choice(["null","1"])
            jump create_character
        "{b}Done":
            show mc at center with ease
            menu confirmation:
                "{i}Is this how you want your character to look?{p}{i}( Changes can be made later! )"
                "Yes":
                    jump clothes_selection
                "No":
                    show mcf at left with ease
                    jump create_character
label clothes_selection:
    mc sad "{i}Sad expression test..."          # for testing: to be removed
    mc worried "{i}Worried expression test..."  # for testing: to be removed
    mc grit "{i}Gritting teeth test..."         # for testing: to be removed
    mc normal "{i}And back to normal.."         # for testing: to be removed
    "{i}Pick some clothes for your character!"
    window hide
    $ index_u, index_s, index_p, index_t, index_c, index_a = 0,0,0,0,0,0
    jump clothes_selection2

label clothes_selection2:
    $ mcf.remove_all()
    python:
        if wardrobe_stockings[index_s]!="":
            mcf.wear(wardrobe_stockings[index_s])
        if wardrobe_pants[index_p]!="":
            mcf.wear(wardrobe_pants[index_p])
        if wardrobe_tops[index_t]!="":
            mcf.wear(wardrobe_tops[index_t])
        if wardrobe_coats[index_c]!="":
            mcf.wear(wardrobe_coats[index_c])
        if wardrobe_accessories[index_a]!="":
            mcf.wear(wardrobe_accessories[index_a])

        ui.frame(xpos=110,ypos=110,xsize=600)
        ui.vbox(xalign=0.5,yalign=0.5)
        ui.hbox(xalign=0.5)
        ui.imagebutton("arrowL.png", "arrowL.png", clicked=ui.returns(("wardrobe_accessories","L")))
        ui.text("Accessories",ypos=7)
        ui.imagebutton("arrowR.png", "arrowR.png", clicked=ui.returns(("wardrobe_accessories","R")))
        ui.close()
        ui.hbox(xalign=0.5)
        ui.imagebutton("arrowL.png", "arrowL.png", clicked=ui.returns(("wardrobe_tops","L")))
        ui.text("Tops",ypos=7)
        ui.imagebutton("arrowR.png", "arrowR.png", clicked=ui.returns(("wardrobe_tops","R")))
        ui.close()
        ui.hbox(xalign=0.5)
        ui.imagebutton("arrowL.png", "arrowL.png", clicked=ui.returns(("wardrobe_pants","L")))
        ui.text("Pants",ypos=7)
        ui.imagebutton("arrowR.png", "arrowR.png", clicked=ui.returns(("wardrobe_pants","R")))
        ui.close()
        ui.hbox(xalign=0.5)
        ui.imagebutton("arrowL.png", "arrowL.png", clicked=ui.returns(("wardrobe_stockings","L")))
        ui.text("Stockings",ypos=7)
        ui.imagebutton("arrowR.png", "arrowR.png", clicked=ui.returns(("wardrobe_stockings","R")))
        ui.close()
        ui.textbutton("{color=#ffffff}Return", clicked=ui.returns("goback"), xalign=0.5)
        ui.close()
    $ picked = ui.interact()
    if picked == "goback":
        jump continue
    if picked[0]=="wardrobe_accessories":
        if picked[1] == "R":
            $ index_a+=1
        else:
            $ index_a-=1
        $ index_a = index_a %len(wardrobe_accessories)

    if picked[0]=="wardrobe_tops":
        if picked[1] == "R":
            $ index_t+=1
        else:
            $ index_t-=1
        $ index_t = index_t %len(wardrobe_tops)

    if picked[0]=="wardrobe_pants":
        if picked[1] == "R":
            $ index_p+=1
        else:
            $ index_p-=1
        $ index_p = index_p %len(wardrobe_pants)

    if picked[0]=="wardrobe_stockings":
        if picked[1] == "R":
            $ index_s+=1
        else:
            $ index_s-=1
        $ index_s = index_s %len(wardrobe_stockings)

    jump clothes_selection2
label continue:
    $ renpy.retain_after_load()
    window show
    "{i}Looks like you're all done! Ready to dive into your adventure!"
    hide mc with Dissolve(.5)
    window hide
    menu:
        "Begin":
            jump start_game
label start_game:
    scene park with Dissolve(1.5)
    "Begin narrative..."

Post Reply

Who is online

Users browsing this forum: No registered users