Page 1 of 1

Adding persistent data to images [SOLVED]

Posted: Wed Apr 15, 2020 4:27 pm
by beastcarving
I've been trying to add persistentdata to may customizable image that I'm using to show and my menus. Can someone show me what I'm going wrong here because none of what I'm doing here is working?

Code: Select all

    image persistent.girl = DynamicDisplayable(draw_girl) 

Code: Select all

    $ persistent.girl = girl
    $ persistent.girl = girl
    $ renpy.save_persistent()

Re: Adding persistent data to images [HELP]

Posted: Thu Apr 16, 2020 12:35 am
by Per K Grok
beastcarving wrote: Wed Apr 15, 2020 4:27 pm I've been trying to add persistentdata to may customizable image that I'm using to show and my menus. Can someone show me what I'm going wrong here because none of what I'm doing here is working?

Code: Select all

    image persistent.girl = DynamicDisplayable(draw_girl) 

Code: Select all

    $ persistent.girl = girl
    $ persistent.girl = girl
    $ renpy.save_persistent()
You might need to explain a bit more clearly what it is you want to do.

Re: Adding persistent data to images [HELP]

Posted: Thu Apr 16, 2020 4:54 am
by beastcarving
I've made a dress-up screen where you can choose a custom look for your character.

Here's the dress-up screen:

Code: Select all

init python:
    dressup_show = False
    dressup_button_show = False
    skin, glasses, dress, hair = 1, 2, 2, 2 # default dressup items
    skin_styles_num, glasses_styles_num, dress_styles_num, hair_styles_num = 2, 3, 4, 2 # number of styles (files) for each dressup item

    def draw_girl(st, at):# same thing as above, just scaled and positioned for the sideimage; there's probably more elegant solution than this...
        return LiveComposite(
            (0, 0),
            (0, 0), im.FactorScale("base.png", 1.5, 1.5),
            (80, 468), im.FactorScale("skin%d.png"%skin, 1.5, 1.5),
            (80, 468), im.FactorScale("dress%d.png"%dress, 1.5, 1.5),
            (80, 468), im.FactorScale("hair%d.png"%hair, 1.5, 1.5),
            (80, 468), im.FactorScale("glasses%d.png"%glasses, 1.5, 1.5)
            ),.1

init:
    image girl = DynamicDisplayable(draw_girl) # using DynamicDisplayable ensures that any changes are visible immedietly
    $ girl = Character('girl', color="#700a1b", show_two_window=True,show_side_image=DynamicDisplayable(draw_girl_side))

    $ persistent.girl == girl
    $ renpy.save_persistent()

#########################################################################
screen dressup_button: # a button to call the dressup game
    if dressup_button_show and not dressup_show:
        imagemap:
            idle "dressstart1.png"
            hover "dressstart2.png"
            hotspot (282, 970, 148, 156) action SetVariable("dressup_show", True)

    #########################################################################
screen dressup:
  if dressup_show:
    add "girl" xalign 0 yalign 0 xpos 0
    python:
        hair_n = hair + 1 # if next hair is chosen
        hair_p = hair - 1 # if previous hair is chosen
        if hair_p < 1: # making sure we don't get out of index range (index 0 is not allowed)
            hair_p = hair_styles_num
        if hair_n > hair_styles_num: # making sure we don't get out of index range (index musn't be bigger than hair_styles_num)
            hair_n = 1

        glasses_n = glasses + 1
        glasses_p = glasses - 1
        if glasses_p < 1:
            glasses_p = glasses_styles_num
        if glasses_n > glasses_styles_num:
            glasses_n = 1

        dress_n = dress + 1
        dress_p = dress - 1
        if dress_p < 1:
            dress_p = dress_styles_num
        if dress_n > dress_styles_num:
            dress_n = 1

        skin_n = skin + 1
        skin_p = skin - 1
        if skin_p < 1:
            skin_p = skin_styles_num
        if skin_n > skin_styles_num:
            skin_n = 1

        
        y = 90
        ui.imagebutton("arrowL.png", "arrowL.png", clicked=SetVariable("hair", hair_p), ypos=y, xpos=10)
        y += 180
        ui.imagebutton("arrowL.png", "arrowL.png", clicked=SetVariable("glasses", glasses_p), ypos=y, xpos=10)
        y += 180
        ui.imagebutton("arrowL.png", "arrowL.png", clicked=SetVariable("dress", dress_p), ypos=90, xpos=190)
        y += 180
        ui.imagebutton("arrowL.png", "arrowL.png", clicked=SetVariable("skin", skin_p), ypos=270, xpos=190)
    textbutton ("Done") action ShowMenu ("main_menu")
I'm having trouble making this custom character remembered after you close and reopen the game. Right now, I'll put a red dress on the customizable characters, and when I'm done dressing her, she will appear on the menu in the red dress as I want, but after I press play on the game or exit the game, the character shown on the menu will go back to a default gray dress, as if she were never customized in the first place.

The custom character is shown on the menu, so you can't save the progress after dressing her.

I'm mainly trying to define this character image "girl" by adding persistent.data in order to finalize how the player chooses to dress their avatar/pov character when closing the game and reopening.

This is the part I'm trying to work on:

Code: Select all

init:
    image girl = DynamicDisplayable(draw_girl) # using DynamicDisplayable ensures that any changes are visible immedietly
    $ girl = Character('girl', color="#700a1b", show_two_window=True,show_side_image=DynamicDisplayable(draw_girl_side))

    $ persistent.girl == girl
    $ renpy.save_persistent()

Re: Adding persistent data to images [HELP]

Posted: Thu Apr 16, 2020 4:44 pm
by Per K Grok
beastcarving wrote: Thu Apr 16, 2020 4:54 am I've made a dress-up screen where you can choose a custom look for your character.

------

I'm having trouble making this custom character remembered after you close and reopen the game. Right now, I'll put a red dress on the customizable characters, and when I'm done dressing her, she will appear on the menu in the red dress as I want, but after I press play on the game or exit the game, the character shown on the menu will go back to a default gray dress, as if she were never customized in the first place.

The custom character is shown on the menu, so you can't save the progress after dressing her.

I'm mainly trying to define this character image "girl" by adding persistent.data in order to finalize how the player chooses to dress their avatar/pov character when closing the game and reopening.

This is the part I'm trying to work on:

Code: Select all

init:
    image girl = DynamicDisplayable(draw_girl) # using DynamicDisplayable ensures that any changes are visible immedietly
    $ girl = Character('girl', color="#700a1b", show_two_window=True,show_side_image=DynamicDisplayable(draw_girl_side))

    $ persistent.girl == girl
    $ renpy.save_persistent()
There are some things in your code I don't get but, however
as far as I can understand your image is defined through 4 values; hair, glasses, dress and skin.

What I would try, would be to save a list with those values as persistent data when exiting and retrieve them when starting a new game.

This is a code that does that. How it could be used in your code I'm not quite sure about. Might give you something to start with though.

Code: Select all

label start:

    if not persistent.attributList:
        $ attList=[0,1,2,3]
    else:
        $ attList=persistent.attributList

    "[attList[0]],[attList[1]],[attList[2]],[attList[3]]"


    $ attList[0]= renpy.input("Set value 1")
    $ attList[1]= renpy.input("Set value 2")
    $ attList[2]= renpy.input("Set value 3")
    $ attList[3]= renpy.input("Set value 4")
    $ persistent.attributList = attList
    $ renpy.save_persistent()
    jump start

Re: Adding persistent data to images [HELP]

Posted: Fri Apr 17, 2020 5:49 am
by beastcarving
Basicly, this is used the group the image items as one displayable image:

Code: Select all

    def draw_girl(st, at): #Scales, positioned, and combine the dressup items into one displayable
        return LiveComposite(
            (0, 0),
            (0, 0), im.FactorScale("base.png", 1.5, 1.5),
            (80, 468), im.FactorScale("skin%d.png"%skin, 1.5, 1.5),
            (80, 468), im.FactorScale("dress%d.png"%dress, 1.5, 1.5),
            (80, 468), im.FactorScale("hair%d.png"%hair, 1.5, 1.5),
            (80, 468), im.FactorScale("glasses%d.png"%glasses, 1.5, 1.5)
            ),.1
so
def draw_girl(st, at)
draw_girl might be what I should add persistent data. I'm having a hard time going about that though.
...................................................
With your code, I've done this:

Code: Select all

    if not persistent.attributList:
        $ girl=[0,1,2,3]
    else:
        $ girl=persistent.attributList

    "[attList[0]],[attList[1]],[attList[2]],[attList[3]]"


    $ girl[0]= (skin)
    $ girl[1]= (glasses)
    $ girl[2]= (dress)
    $ girl[3]= (hair)
    $ persistent.attributList = girl
    $ renpy.save_persistent()
    return
It remembers the set values, but doesn't actually remember the image items in a visual way, so the character's appearance remains unsaved, but not the values selected.

Re: Adding persistent data to images [HELP]

Posted: Fri Apr 17, 2020 1:42 pm
by xavimat
Are you sure you need persistent variables at all? Can't you use normal variables, default them, change them in the screen and save them as a normal save? That should work.

Note that "persistent" variables are shared between saves. So, if you start a new game, you'll find the values of the persistent from former gameplays.

Re: Adding persistent data to images [HELP]

Posted: Fri Apr 17, 2020 1:53 pm
by beastcarving
That won't work for what I'm trying to do. I need the dress up girl progress to save after exiting the game and reopening it should save your progress.

Re: Adding persistent data to images [HELP]

Posted: Fri Apr 17, 2020 3:01 pm
by Per K Grok
beastcarving wrote: Fri Apr 17, 2020 5:49 am Basicly, this is used the group the image items as one displayable image:

Code: Select all

    def draw_girl(st, at): #Scales, positioned, and combine the dressup items into one displayable
        return LiveComposite(
            (0, 0),
            (0, 0), im.FactorScale("base.png", 1.5, 1.5),
            (80, 468), im.FactorScale("skin%d.png"%skin, 1.5, 1.5),
            (80, 468), im.FactorScale("dress%d.png"%dress, 1.5, 1.5),
            (80, 468), im.FactorScale("hair%d.png"%hair, 1.5, 1.5),
            (80, 468), im.FactorScale("glasses%d.png"%glasses, 1.5, 1.5)
            ),.1
so
def draw_girl(st, at)
draw_girl might be what I should add persistent data. I'm having a hard time going about that though.
...................................................
With your code, I've done this:

Code: Select all

    if not persistent.attributList:
        $ girl=[0,1,2,3]
    else:
        $ girl=persistent.attributList

    "[attList[0]],[attList[1]],[attList[2]],[attList[3]]"


    $ girl[0]= (skin)
    $ girl[1]= (glasses)
    $ girl[2]= (dress)
    $ girl[3]= (hair)
    $ persistent.attributList = girl
    $ renpy.save_persistent()
    return
It remembers the set values, but doesn't actually remember the image items in a visual way, so the character's appearance remains unsaved, but not the values selected.
Ok. The line

"[attList[0]],[attList[1]],[attList[2]],[attList[3]]"

don't have any function in your version of the code since you are using a list named "girl" instead of "attList"

In my version it was a way to check if the program had fetched the persistent data.

In your version this should be the place to put your image together using the persistent data.

Also, the default girl list does not necessarily have to be [0,1,2,3] it could be [0,0,0,0] or what ever values you want to have as a start position for each attribute before any persistent data has been saved.

Re: Adding persistent data to images [HELP]

Posted: Fri Apr 17, 2020 4:47 pm
by MaydohMaydoh
Could you not just create a persistent dict with all the variables?

Code: Select all

default persistent.dDress = { "skin" : 1, "glasses" : 2, "dress" : 2, "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['skin']), 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)

screen dressup():
    add 'girl' align (0, 0)
    ## other stuff here ##
    
    hbox:
        textbutton "<" action SetDict(persistent.dDress, 'skin', persistent.dDress['skin'] - 1)
        text "Skin"
        textbutton ">" action SetDict(persistent.dDress, 'skin', persistent.dDress['skin'] + 1)
        ##etc...
I tested that and it persists after closing and reopening the game.

You could also probably create your own screen action to simplify the other part in the dressing screen.

Code: Select all

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()

screen dressing():
    add 'girl' align (0.0, 0.0)
    hbox:
        textbutton "<" action DressUp(persistent.dDress, 'skin', -1, 2)
        text "Skin"
        textbutton ">" action SetDict(persistent.dDress, 'skin', 1, 2)
Will increase or decrease and when it gets to 0, the value is changed to the max amount and when it gets to the max amount, the value is changed to 0.

Edit: Changed how persistent.dDress is defined as it previously didn't work correctly.
You could use a function and the Function action instead. Probably better that way rather than making a new action. ops

Re: Adding persistent data to images [HELP]

Posted: Sat Apr 18, 2020 6:45 am
by beastcarving
Thanks! It works nicely.

Re: Adding persistent data to images [SOLVED]

Posted: Mon Apr 20, 2020 5:00 am
by beastcarving
Sorry, I have one more question, since we are on this topic, I wanted to know how to use an if-else statement with the dress-up items:

Code: Select all

define persistent.dDress = { "skin" : {"skin1", "skin2", "skin3"}, "glasses" : 3, "dress" : 4, "hair" : 2 }
I'm not too familiar with doing a dress up screen this way, so I got lost when trying to add this. I'm trying to add something like this:

Code: Select all

screen dressing():
    imagemap:
        ground "10white.jpg"
    add 'girl' xalign 0 ypos 468 xpos 120
    if persistent.dressup =="skin1":
        add "face2.png" ypos 468 xpos 120 zoom 1.5

    elif persistent.dressup =="skin2":
        add "face1.png" ypos 468 xpos 120 zoom 1.5

    elif persistent.dressup =="skin3":
        add "face3.png" ypos 468 xpos 120 zoom 1.5

Re: Adding persistent data to images [SOLVED]

Posted: Wed Apr 22, 2020 8:36 pm
by beastcarving
nvm. I figured it out.