Sorry if this is a dumb question, but how do I check the persistent scope for a variable using a variable? I'm more familiar with other programming languages and haven't been able to figure out the python/ren'py syntax...
Instead of...
if persistent.unlock_music
something like...
$ myvar = "unlock_music"
if persistent[myvar]
Thanks.
Checking Persistent Variables
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.
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.
-
- Newbie
- Posts: 7
- Joined: Tue Nov 01, 2016 12:31 pm
- Contact:
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Checking Persistent Variables
Let me see if I understood you correct.
You want to use a variable as a check for a persistent variable?
Can't say I have any experience with this, nor do I expect it to work, but can you try
But what is your goal with this? It seems unnecessarily complicated.
define myvar = persistent.[myvar] may work, but might confuse renpy.
You want to use a variable as a check for a persistent variable?
Can't say I have any experience with this, nor do I expect it to work, but can you try
Code: Select all
default myvar = "bob"
label start:
Code: Select all
$ myvar = "unlock_music"
$ persistent.[myvar] = True
if persistent.[myvar]:
$ do.something
define myvar = persistent.[myvar] may work, but might confuse renpy.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
-
- Newbie
- Posts: 7
- Joined: Tue Nov 01, 2016 12:31 pm
- Contact:
Re: Checking Persistent Variables
I have a screen that displays character stats, so I'm passing in a variable to know which character to display...
use characters(character)
One of the things I'm using the "character" variable for is to check if the character is unlocked or if I need to display a locked message, so using something like "if persistent[character]" prevents me from having to hard-code a check for every single character. The benefit is if I add more characters in the future, I don't need to update this screen.
Every other programming language I've used has a way to do this, so I'm assuming it's possible, I just can't figure out the syntax. Is there maybe a function like persistent.get(character) I could use?
And thanks for your suggestion, but it did not work.
use characters(character)
One of the things I'm using the "character" variable for is to check if the character is unlocked or if I need to display a locked message, so using something like "if persistent[character]" prevents me from having to hard-code a check for every single character. The benefit is if I add more characters in the future, I don't need to update this screen.
Every other programming language I've used has a way to do this, so I'm assuming it's possible, I just can't figure out the syntax. Is there maybe a function like persistent.get(character) I could use?
And thanks for your suggestion, but it did not work.
- Ocelot
- Lemma-Class Veteran
- Posts: 2402
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Checking Persistent Variables
You can use python built-in function: https://docs.python.org/2/library/funct ... ml#getattr
Code: Select all
if getattr(persistent, character, None):
# Something
< < insert Rick Cook quote here > >
-
- Newbie
- Posts: 7
- Joined: Tue Nov 01, 2016 12:31 pm
- Contact:
Re: Checking Persistent Variables
This is perfect... thank you!
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot]