Using persistent data with image buttons [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
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Using persistent data with image buttons [solved!]

#1 Post by yuucie »

I posted about this problem in a previous thread, but it wasn't too related to the topic at hand so I thought I should make it seperate :?

I'm making a bonus section where bonus stories are unlocked upon completing a best end of a char. I set up the screen to have a line of image buttons on the side, in which, if the endings have not been seen, it'll be showing a ??? image. If it's unlocked, it'll show the name of the character that has been unlocked.

Image

This is my code so far:

Code: Select all

screen Extras:

    # This ensures that any other menu screen is replaced.
    tag menu
    
    add "UI/Extras BG.png"
    
    if persistent.Char1End is True:
        imagebutton auto "UI/Extras Char1_%s.png" action NullAction() xalign 0.025 yalign 0.2 focus_mask True
    else:
        imagebutton auto "UI/Extras locked button_%s.png" action NullAction() xalign 0.025 yalign 0.2 focus_mask True
    
    
    if persistent.Char2End is True:
        imagebutton auto "UI/Extras Char2_%s.png" action NullAction() xalign 0.025 yalign 0.2 focus_mask True
    else:
        imagebutton auto "UI/Extras locked button_%s.png" action NullAction() xalign 0.025 yalign 0.2 focus_mask True
The first button works fine, but the second button is already unlocked when it isn't meant to be (the persistent.Char2End has not even been programmed into the game script yet, so it cannot be unlocked). I believe it's still reading off Char1's if statement and showing an unlocked state (since persistent.Char1End hasn't been seen, renpy is reading the else: statement to show a locked button for Char1, and also the unlocked button for Char2 since it's next on the list). I don't know how to fix this :oops: Help would be appreciated!
Last edited by yuucie on Sun Sep 28, 2014 4:19 pm, edited 1 time in total.

User avatar
feathersnake
Regular
Posts: 104
Joined: Fri Apr 13, 2012 8:05 pm
Completed: A Rose by Any Other Name
Projects: Color, You've Got Mail!
Organization: Olfix Productions
Tumblr: olfix
Deviantart: olfix
Contact:

Re: Using persistent data with image buttons

#2 Post by feathersnake »

I can't seem to replicate your problem with the code you posted. It's working fine for me, even with persistent.Char2End not being set to true anywhere in the code. I didn't use auto because I didn't feel like saving that many images though. Also, in the code you posted, your buttons are in the exact same spot so I moved the second one down a bit.

The only thing I can think of is to try putting this at the top of your script somewhere (before start).

Code: Select all

$ persistent.Char2End = False
Olfix Productions:
Tumblr | itch.io
Complete Projects:
A Rose by Any Other Name
In-progress:
Color | You've Got Mail!

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Using persistent data with image buttons [solved]

#3 Post by yuucie »

Whoops! I copy-pasted the first code over the second (to get rid of un-necessary code involving a side image flashing on hover) and forgot to change the positions. I'm sorry for the confusion, it wasn't meant to be in the same place as the first in the original code. My bad!
Code:
$ persistent.Char2End = False
This worked! I have no idea why it was set to True on default, but thank you! I have a question: When my game is over I do a renpy.restart. Will that reset the persistent variable to False again?
Last edited by yuucie on Sun Sep 28, 2014 3:41 pm, edited 1 time in total.

User avatar
feathersnake
Regular
Posts: 104
Joined: Fri Apr 13, 2012 8:05 pm
Completed: A Rose by Any Other Name
Projects: Color, You've Got Mail!
Organization: Olfix Productions
Tumblr: olfix
Deviantart: olfix
Contact:

Re: Using persistent data with image buttons

#4 Post by feathersnake »

Awesome! Good luck with the rest of your project. ^^
Olfix Productions:
Tumblr | itch.io
Complete Projects:
A Rose by Any Other Name
In-progress:
Color | You've Got Mail!

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Using persistent data with image buttons [solved]

#5 Post by xavimat »

yuucie wrote:I have a question: When my game is over I do a renpy.restart. Will that reset the persistent variable to False again?
No. The persistent variables don't change with renpy.full_restart(), they remain "persistent" also when the program is closed and re-executed.
http://renpy.org/doc/html/persistent.html
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
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Using persistent data with image buttons

#6 Post by yuucie »

Ah thank you, I was worried that the code $ persistent.Char2End = False will reset it to False. Thanks for all the help!

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Using persistent data with image buttons

#7 Post by xavimat »

yuucie wrote:Ah thank you, I was worried that the code $ persistent.Char2End = False will reset it to False. Thanks for all the help!
Mmm, sorry. Yes, that line of code actually does that.
But I don't know really why you have this problem. The code you've posted in the OP seems correct to me (except for the position of the 2nd button).

EDIT: Try to delete persistent data with the launcher. And not use that line ($ persistent.Char2End = False).
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
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Using persistent data with image buttons

#8 Post by yuucie »

xavimat wrote:
EDIT: Try to delete persistent data with the launcher. And not use that line ($ persistent.Char2End = False).
Oh my goodness, I tried as you suggested (and blocked out the line like you said) and it's working....that's really odd, since I haven't defined persistent.Char2End anywhere except in the bonus section. Well it looks like it really is working this time!! Thanks again!

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Using persistent data with image buttons [solved!]

#9 Post by xavimat »

That's the magic of "persistent" variables. They can be used before being defined, and they return "None".
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)

Post Reply

Who is online

Users browsing this forum: Google [Bot]