Adding persistent data to images [SOLVED]

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: 122
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:

Adding persistent data to images [SOLVED]

#1 Post by beastcarving » 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()
Last edited by beastcarving on Sat Apr 18, 2020 6:45 am, edited 1 time in total.
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
Per K Grok
Miko-Class Veteran
Posts: 718
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1 & 2
itch: per-k-grok
Location: Sverige
Contact:

Re: Adding persistent data to images [HELP]

#2 Post by Per K Grok » Thu Apr 16, 2020 12:35 am

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.

User avatar
beastcarving
Regular
Posts: 122
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: Adding persistent data to images [HELP]

#3 Post by beastcarving » Thu Apr 16, 2020 4:54 am

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()
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
Per K Grok
Miko-Class Veteran
Posts: 718
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1 & 2
itch: per-k-grok
Location: Sverige
Contact:

Re: Adding persistent data to images [HELP]

#4 Post by Per K Grok » Thu Apr 16, 2020 4:44 pm

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

User avatar
beastcarving
Regular
Posts: 122
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: Adding persistent data to images [HELP]

#5 Post by beastcarving » 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.
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
xavimat
Eileen-Class Veteran
Posts: 1446
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Adding persistent data to images [HELP]

#6 Post by xavimat » Fri Apr 17, 2020 1:42 pm

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.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
beastcarving
Regular
Posts: 122
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: Adding persistent data to images [HELP]

#7 Post by beastcarving » Fri Apr 17, 2020 1:53 pm

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.
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
Per K Grok
Miko-Class Veteran
Posts: 718
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1 & 2
itch: per-k-grok
Location: Sverige
Contact:

Re: Adding persistent data to images [HELP]

#8 Post by Per K Grok » Fri Apr 17, 2020 3:01 pm

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.

User avatar
MaydohMaydoh
Regular
Posts: 162
Joined: Mon Jul 09, 2018 5:49 am
Projects: Fuwa Fuwa Panic
Tumblr: maydohmaydoh
Location: The Satellite of Love
Contact:

Re: Adding persistent data to images [HELP]

#9 Post by MaydohMaydoh » Fri Apr 17, 2020 4:47 pm

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

User avatar
beastcarving
Regular
Posts: 122
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: Adding persistent data to images [HELP]

#10 Post by beastcarving » Sat Apr 18, 2020 6:45 am

Thanks! It works nicely.
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: 122
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: Adding persistent data to images [SOLVED]

#11 Post by beastcarving » Mon Apr 20, 2020 5:00 am

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
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: 122
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: Adding persistent data to images [SOLVED]

#12 Post by beastcarving » Wed Apr 22, 2020 8:36 pm

nvm. I figured it out.
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: Google [Bot]