Is it possible lock/unlock replay with variables?

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
tcassat
Regular
Posts: 33
Joined: Tue Oct 03, 2017 7:32 pm
Contact:

Is it possible lock/unlock replay with variables?

#1 Post by tcassat »

Hello. In my project I use a gallery of replays in the standard way, ie the scenes are locked until the player sees them at least once. From then on, he can see the replay whenever he wants. For this, I use "locked = none", as in the line below:

Code: Select all

textbutton "First Event" action Replay("event_1",locked=None)
But besides the replays, I also want to put some special scenes in the same gallery. For this, I use locked = True, since I do not want the player to have immediate access to these special scenes:

Code: Select all

textbutton "Special 1" action Replay("special_1",locked=True)
The problem: the replay stays locked forever. How do I place a conditional statement above so that "locked=True" if variable x=0 and "locked=False" if x=1?

Thanks.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Is it possible lock/unlock replay with variables?

#2 Post by PyTom »

Code: Select all

textbutton "Special 1" action Replay("special_1",locked=renpy.seen_label("event_1"))
Or in general, you can use any True/False condition with locked.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

tcassat
Regular
Posts: 33
Joined: Tue Oct 03, 2017 7:32 pm
Contact:

Re: Is it possible lock/unlock replay with variables?

#3 Post by tcassat »

Thanks. Just out of curiosity, what would the command line look like with True/False condition with locked?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Is it possible lock/unlock replay with variables?

#4 Post by Remix »

Any python conditional expression can return True or False, so you basically just want a test that evaluates True only when you want it locked.
On PyTom's example, the function renpy.seen_label("event_1") is a utility that simply returns True or False if a named label has been seen.

Personally (for simplicity) I'd tend to directly use a variable in your inline code that uses True/False (note the capitals and no "" quotes) and is True when lock is active, then just:

textbutton "Special 1" action Replay( "special_1", locked = special_1_locked )

With the usual:
default special_1_locked = True # reading this we can pretty much guess what the variable does

and (at some point in the code - likely in a label)
$ special_1_locked = False # unlocked now
Frameworks & Scriptlets:

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Is it possible lock/unlock replay with variables?

#5 Post by PyTom »

You probably want persistent.special_1_locked in both cases.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Bing [Bot]