Conditional Buttons?

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
Nella102
Newbie
Posts: 2
Joined: Mon Oct 19, 2020 11:47 am
Contact:

Conditional Buttons?

#1 Post by Nella102 » Sun Oct 25, 2020 11:10 pm

I was wondering if it was possible to have a conditional button in the main menu. So, for instance, if you finish chapter 1, it will remove the "start" button and will replace it with Start Chap. 2 or something similar. Whenever I try using an if statement using a variable named "Chapter2Start" it doesn't allow me to define the variable before the screen loads. How can I fix this? (Can I also make the Chapter 2 Button stay every time you open the game after that?)

User avatar
gas
Miko-Class Veteran
Posts: 838
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Conditional Buttons?

#2 Post by gas » Thu Oct 29, 2020 5:41 pm

Use a persistent. and default.
Defaults are variables that are defined at the init phase, so they are here before the main menu is staged. anyway, persistent return None if not defined (so, no error anyway) and are preserved between launches.
Add this at the very beginning of your script, out of any label.

default persistent.finished_chapt_1 = False

At the end of chapter 1, use
$ persistent.finished_chapt_1 = True

In the main menu you can check the condition easily.

if persistent.finished_chapt_1:
# the chapter 1 button
else:
# the chapter 2 button
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Post Reply

Who is online

Users browsing this forum: No registered users