Making Conditional Texbuttons

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
FamuFamu
Regular
Posts: 111
Joined: Thu Oct 11, 2012 4:52 pm
Contact:

Making Conditional Texbuttons

#1 Post by FamuFamu » Wed May 08, 2013 4:05 am

I have this "Index" screen of sorts, where you can access journal entries, here's a bit of the code for it...

Code: Select all

screen notes_screen:
    
    default journal_entry = "Index"
    
    tag menu
    use navigation
    vbox:
        xminimum 620
        xmaximum 620
        frame:
            yminimum 593
            ymaximum 593
            style_group "pref"
            has vbox
            
            if journal_entry == "Index":
                
                textbutton "Page 1" action SetScreenVariable("journal_entry", "page_1")
                textbutton "Page 2" action SetScreenVariable("journal_entry", "page_2")
                
            if journal_entry == "page_1":
                
                label _("Hello World")
                label _("I hate ye")
                
            if journal_entry == "page_2":
                
                label _("Page")
                label _("Number two")
            
    vbox:
        xpos 607
        xmaximum 140
        frame:
            style_group "pref"
            has vbox
            
            textbutton _("Index") action SetScreenVariable("journal_entry", "Index")
        
            
The result looks like this

Image

What I want is to make the textbuttons only appear if a variable is set to True, so they unlock with each ending. How can I do that?

(Also, is there a way to center the textbuttons inside the vbox?)

Thanks in advance

RangerDanger
Regular
Posts: 45
Joined: Wed Jun 27, 2012 11:36 pm
Contact:

Re: Making Conditional Texbuttons

#2 Post by RangerDanger » Wed May 08, 2013 10:46 am

You would just put the textbutton statements inside and if block

Code: Select all

if some_boolean_expression:
    textbutton "Page 1" action SetScreenVariable("journal_entry", "page_1")

User avatar
FamuFamu
Regular
Posts: 111
Joined: Thu Oct 11, 2012 4:52 pm
Contact:

Re: Making Conditional Texbuttons

#3 Post by FamuFamu » Wed May 08, 2013 11:24 am

Huh... I guess I suffered from a "Tunnel vision" of sorts thinking that some fancy screen language would be needed and I ignored the most simple explanation.

Thanks for the reply

Post Reply

Who is online

Users browsing this forum: No registered users