Hello!
I know persistent variables when not decalred, default to None. So i usually had never declared them until recently. But i see here and there people do it and then again some not. I assume both is ok to do, but i wonder what is better?
Declare persistent variables or not?
Declare 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.
-
- Regular
- Posts: 169
- Joined: Sun Jun 04, 2017 12:05 pm
- Completed: Too many, check signature
- Deviantart: mikolajspy
- Location: Wrocław, Poland
- Contact:
Re: Declare persistent variables?
I'm not programming expert, but in most languages it's better to properly declare any variable that you're going to use globally.
I believe it matters especially when you use persistent in some True/False check or as a counter.
I believe it matters especially when you use persistent in some True/False check or as a counter.
Re: Declare persistent variables?
Personally I see each persistent variable having 3 states:
None: Player never hit the code that sets the variable
True: Player hit the code that sets the variable once
False: Player has hit the code at some point, but it's been reset to False
You'd test the 3 states by:
If you're not interested in the None state, then just ditch the is None statement.
None: Player never hit the code that sets the variable
True: Player hit the code that sets the variable once
False: Player has hit the code at some point, but it's been reset to False
You'd test the 3 states by:
Code: Select all
if persistent.var:
"True"
elif persistent.var is None:
"None"
else:
"False"
Who is online
Users browsing this forum: Ahrefs [Bot], AWizardWithWords