Tips for how to structure if statements when creating menus?

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
NocturneLight
Regular
Posts: 163
Joined: Thu Jun 30, 2016 1:20 pm
Projects: Unsound Minds: The Clarevine Epoch
Organization: Reminiscent 64
Tumblr: Reminiscent64
itch: Reminiscent64
Location: Texas
Contact:

Tips for how to structure if statements when creating menus?

#1 Post by NocturneLight »

I'm messing with transforms now that I've finally figured out how to get them to work.

I've managed to get Spring 1 to show a list of dates or make the list of dates disappear. I've also managed to get the list of dates to scroll up and down.

However, when I press the Spring button, then press down on the keyboard to make the list of dates scroll down, then press the Spring button again,

Code: Select all

if show_buttons:
            at date_buttons_appear 
completely fails and ceases to work.



My guess is that I'm going to have to come up with an if statement for every possible combination of boolean variables if I'm going to create a menu screen using transforms.

Am I correct in my assumption? If not, how would you recommend coding a menu screen using if statements? Or could it be that if statements are the wrong way to go about triggering transforms for the menu screen? If that is possibly the case, then what other way would you do it?


If it helps, here's my code:

Code: Select all

## The script of the game goes in this file.

init python:
    page_ID_min = 1
    page_ID_max = 2
    button_ID_min = 1
    button_ID_max = 15
    
    def next_page():
        global page_ID
        
        page_ID = max(page_ID_min, min(page_ID_max, page_ID + 1))
        
        renpy.retain_after_load()
        renpy.restart_interaction()
        
    def previous_page():
        global page_ID
        
        page_ID = max(page_ID_min, min(page_ID_max, page_ID - 1))
        
        renpy.retain_after_load()
        renpy.restart_interaction()

## Declare characters used by this game. The color argument colorizes the name
## of the character.

define e = Character('Eileen')

# Declare a variable used in init python so that we can use it inside a screen.
define page_ID = page_ID_min


## The game starts here.

screen Page_Selector:
    modal True
    
    
    window:
        background "#000"
        area(0, 0, 1300, 750)

    vbox:
        text "Page [page_ID] of page [page_ID_max]"
        text "show_buttons: [show_buttons]   down_pressed: [down_pressed]   up_pressed: [up_pressed]" xalign 0.5
        key "K_RIGHT" action next_page
        key "K_LEFT" action previous_page
        key "K_x" action Show("Page_Content", Dissolve(1)), Hide("Page_Selector", Dissolve(1))
        key "K_z" action Hide("Page_Selector", Dissolve(1))
        
        textbutton "Next Page":
            if page_ID < page_ID_max:
                action next_page
        
        textbutton "Previous Page":
            if page_ID > page_ID_min:
                action previous_page
                
    vbox xalign 0.2 yalign 0.36:
        
        spacing 25
        textbutton "Spring" action ToggleVariable("show_buttons", True, False)
        textbutton "Summer" action NullAction()
        textbutton "Fall" action NullAction()
        textbutton "Winter" action NullAction()
    
    vbox spacing 25:
        
        key "K_DOWN" action SetVariable("down_pressed", True), SetVariable("up_pressed", False)
        key "K_UP" action SetVariable("up_pressed", True), SetVariable("down_pressed", False)
        
        
        
        textbutton "Spring 1"
        
        if show_buttons:
            at date_buttons_appear   
        
        if up_pressed:
            at date_buttons_scroll_up
        
        if down_pressed:
            at date_buttons_scroll_down
        
        if show_buttons == False:
            at date_buttons_disappear
        
        
        
screen Page_Content:
    modal True
    window:
        background "#001"
        area(0, 0, 1300, 750)
    vbox:
        text "You are at [page_ID]"
        
        key "K_x" action Hide("Page_Content", Dissolve(1)), Show("Page_Selector", Dissolve(1))
        key "K_z" action Hide("Page_Content", Dissolve(1)), Hide("Page_Selector", Dissolve(1))
        
        
        textbutton "Back" action Hide("Page_Content", Dissolve(1)), Show("Page_Selector", Dissolve(1))
        

        
#Define any transformations here.
transform date_buttons_appear:
    subpixel True
    xalign 0.4 # this will center the main menu
    alpha 0.0 yalign 0.6 xanchor 0.0 yanchor 0.32 # this will position the main menu at the bottom, outside of the screen
    parallel:
        easein 1.0 alpha 1.0
    parallel:
        easein 1.0 xanchor 1.0 #changing yanchor from 0 to 1 we make the menu appear 

transform date_buttons_disappear:
    subpixel True
    xalign 0.4 # this will center the main menu
    alpha 1.0 yalign 0.6 xanchor 1.0 yanchor 0.32 # this will position the main menu at the bottom, outside of the screen
    parallel:
        easein 1.0 alpha 0.0
    parallel:
        easein 1.0 xanchor 0.0 #changing yanchor from 0 to 1 we make the menu appear 
        
transform date_buttons_disappear_while_up:
    xalign 0.4 yalign 0.58
    alpha 1.0
    parallel:
        easein 1.0 alpha 0.0
    parallel:
        easein 1.0 xalign 0.5
 
transform date_buttons_scroll_down:
    subpixel True
    
    xalign 0.4 yalign 0.6 xanchor 1.0 yanchor 0.32
    parallel:
        easein 1.0 xanchor 1.0 yanchor 0.76
        

transform date_buttons_scroll_up:
    subpixel True
    
    xalign 0.4 yalign 0.6 xanchor 1.0 yanchor 0.76
    parallel:
        easein 1.0 xanchor 1.0 yanchor 0.32        

init python:
    #Define other variables here.
    show_buttons = None
    up_pressed = None
    down_pressed = None
        
label start:
    show screen Page_Selector
    ## Show a background. This uses a placeholder by default, but you can add a
    ## file (named either "bg room.png" or "bg room.jpg") to the images
    ## directory to show it.

    scene bg room

    ## This shows a character sprite. A placeholder is used, but you can replace
    ## it by adding a file named "eileen happy.png" to the images directory.

    show eileen happy

    ## These display lines of dialogue.

    "Hello, world."

    e "You've created a new Ren'Py game."

    e "Once you add a story, pictures, and music, you can release it to the world!"

    ## This ends the game.

    return
Ignore the fact that there's only one button, I took out the 14 others right now so that I wouldn't be so overwhelmed by the code.

Also ignore the fact that the button is showing in the corner in the beginning. I'll fix that once I've got the menu movements working.

Also ignore the unused transforms. I'm trying to implement them one by one.
The Old Guard is at His Limit. The time is near to usher in the New Guard.

The Great Horror is soon to be free.

Clarevine is the key.


"Unsound Minds: The Clarevine Epoch" is a yuri visual novel that shatters english visual novel norms and aims to blend Christianity and the Cthulhu Mythos to tell a deep and dark story that you'll enjoy. You can follow the Kickstarter here.

Stay sound and persist through the chaos,
NocturneLight

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

Re: Tips for how to structure if statements when creating me

#2 Post by gas »

Well, everything stand in how you store variables.
There's no way to return to
show_buttons = None
up_pressed = None
down_pressed = None

and that's mess everything.
So, when you hide the date, also set up_pressed = None and down_pressed = None, that's really so easy!

Code: Select all

 textbutton "Spring" action (ToggleVariable("show_buttons", True, False), SetVariable("up_pressed", False), SetVariable("down_pressed", False))
You'll pay me a beer later.
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

User avatar
NocturneLight
Regular
Posts: 163
Joined: Thu Jun 30, 2016 1:20 pm
Projects: Unsound Minds: The Clarevine Epoch
Organization: Reminiscent 64
Tumblr: Reminiscent64
itch: Reminiscent64
Location: Texas
Contact:

Re: Tips for how to structure if statements when creating me

#3 Post by NocturneLight »

The advice was very helpful, gas. Thank you.

I managed to make some progress. Though I am stuck on something else now.

When I press the Spring, Summer, Fall, or Winter buttons, and then press up on the keyboard, the date_buttons_scroll_up transformation occurs when it shouldn't.

The only solution I've come up with is using this:

Code: Select all

if up_pressed != False or down_pressed != False:
            key "K_UP" action SetVariable("up_pressed", True), SetVariable("down_pressed", False)
            
        key "K_DOWN" action SetVariable("down_pressed", True), SetVariable("up_pressed", False)

Now, this solves one problem but creates another. The user can't scroll up if he can't, but this messes with the date_buttons_scroll_down transformation. For whatever reason, applying an if statement to key presses goes and changes the positions specified in the transformation the first time you press the down key after you press one of the season buttons. Anytime after that and the transformation runs smoothly.

I feel like I've tried everything I could think of that could fix it, but no dice so far.

Any ideas that I might not have thought of that could fix this?

Thanks.

Here's what I've got right now:

Code: Select all

screen Page_Selector:
    modal True
    
    
    window:
        background "#000"
        area(0, 0, 1300, 750)

    vbox:
        text "Page [page_ID] of page [page_ID_max]"
        text "show_buttons: [show_buttons]   up_pressed: [up_pressed], down_pressed: [down_pressed]   show_buttons_spring: [show_buttons_spring]   show_buttons_summer: [show_buttons_summer]"
        key "K_RIGHT" action next_page
        key "K_LEFT" action previous_page
        key "K_x" action Show("Page_Content", Dissolve(1)), Hide("Page_Selector", Dissolve(1))
        key "K_z" action Hide("Page_Selector", Dissolve(1))
        
        textbutton "Next Page":
            if page_ID < page_ID_max:
                action next_page
        
        textbutton "Previous Page":
            if page_ID > page_ID_min:
                action previous_page
                
    vbox xalign 0.2 yalign 0.36:
        
        spacing 25
        textbutton "Spring" action ToggleVariable("show_buttons_spring", True, False), SetVariable("show_buttons_summer", None), SetVariable("show_buttons_fall", None), SetVariable("show_buttons_winter", None), SetVariable("up_pressed", False), SetVariable("down_pressed", False)
        textbutton "Summer" action ToggleVariable("show_buttons_summer", True, False), SetVariable("show_buttons_spring", None), SetVariable("show_buttons_fall", None), SetVariable("show_buttons_winter", None), SetVariable("up_pressed", False), SetVariable("down_pressed", False)
        textbutton "Fall" action ToggleVariable("show_buttons_fall", True, False), SetVariable("show_buttons_spring", None), SetVariable("show_buttons_summer", None), SetVariable("show_buttons_winter", None), SetVariable("up_pressed", False), SetVariable("down_pressed", False)
        textbutton "Winter" action ToggleVariable("show_buttons_winter", True, False), SetVariable("show_buttons_spring", None), SetVariable("show_buttons_summer", None), SetVariable("show_buttons_fall", None), SetVariable("up_pressed", False), SetVariable("down_pressed", False)
        
    vbox spacing 25:
        
        #Depending on the truth values, you get access to certain keys.
        if up_pressed != False or down_pressed != False:
            key "K_UP" action SetVariable("up_pressed", True), SetVariable("down_pressed", False)
            
        key "K_DOWN" action SetVariable("down_pressed", True), SetVariable("up_pressed", False)
        
        #Depending on the truth values, certain transforms occur.
        if show_buttons_spring == True:
            at date_buttons_appear
            textbutton "Spring 1"
            
        if show_buttons_spring == False and show_buttons_summer == None and show_buttons_fall == None and show_buttons_winter == None:
            at date_buttons_disappear
            textbutton "Spring 1"

        if show_buttons_summer == True:
            at date_buttons_appear
            textbutton "Summer 1"
        
        if show_buttons_summer == False and show_buttons_spring == None and show_buttons_fall == None and show_buttons_winter == None:
            at date_buttons_disappear
            textbutton "Summer 1"
    
        if show_buttons_fall == True:
            at date_buttons_appear
            textbutton "Fall 1"
        
        if show_buttons_fall == False and show_buttons_spring == None and show_buttons_summer == None and show_buttons_winter == None:
            at date_buttons_disappear
            textbutton "Fall 1"
        
        if show_buttons_winter == True:
            at date_buttons_appear
            textbutton "Winter 1"
        
        if show_buttons_winter == False and show_buttons_spring == None and show_buttons_summer == None and show_buttons_fall == None:
            at date_buttons_disappear
            textbutton "Winter 1"
           

        
        if down_pressed == True:
            at date_buttons_scroll_down
            
        
        if up_pressed == True:
            at date_buttons_scroll_up
The Old Guard is at His Limit. The time is near to usher in the New Guard.

The Great Horror is soon to be free.

Clarevine is the key.


"Unsound Minds: The Clarevine Epoch" is a yuri visual novel that shatters english visual novel norms and aims to blend Christianity and the Cthulhu Mythos to tell a deep and dark story that you'll enjoy. You can follow the Kickstarter here.

Stay sound and persist through the chaos,
NocturneLight

User avatar
NocturneLight
Regular
Posts: 163
Joined: Thu Jun 30, 2016 1:20 pm
Projects: Unsound Minds: The Clarevine Epoch
Organization: Reminiscent 64
Tumblr: Reminiscent64
itch: Reminiscent64
Location: Texas
Contact:

Re: Tips for how to structure if statements when creating me

#4 Post by NocturneLight »

An update.

I still haven't figured out a solution.

However, I am noticing something with the code.

I've already mentioned that doing this:

Code: Select all

if up_pressed != False or down_pressed != False:
    key "K_UP" action SetVariable("up_pressed", True), SetVariable("down_pressed", False)
            
key "K_DOWN" action SetVariable("down_pressed", True), SetVariable("up_pressed", False)
tampers with the positions specified by the transform.



Besides this, I am also noticing that if you nest that code, it also screws with any transforms that are before the if statement but still nested inside the same thing as the if statement.

For example:

Code: Select all

if show_buttons_spring == True:
    at date_buttons_appear
    textbutton "Spring 1"
    if up_pressed != False or down_pressed != False:
        key "K_UP" action SetVariable("up_pressed", True), SetVariable("down_pressed", False)
            
    key "K_DOWN" action SetVariable("down_pressed", True), SetVariable("up_pressed", False)

That code shows not just the date_buttons_scroll_up transform as screwed up the first time around, but also shows the date_buttons_appear transform as screwed up.


I almost think this might be a bug at this point, to be quite honest. Brownie points if anyone can figure out what I'm doing wrong if it's not a bug though.
The Old Guard is at His Limit. The time is near to usher in the New Guard.

The Great Horror is soon to be free.

Clarevine is the key.


"Unsound Minds: The Clarevine Epoch" is a yuri visual novel that shatters english visual novel norms and aims to blend Christianity and the Cthulhu Mythos to tell a deep and dark story that you'll enjoy. You can follow the Kickstarter here.

Stay sound and persist through the chaos,
NocturneLight

User avatar
NocturneLight
Regular
Posts: 163
Joined: Thu Jun 30, 2016 1:20 pm
Projects: Unsound Minds: The Clarevine Epoch
Organization: Reminiscent 64
Tumblr: Reminiscent64
itch: Reminiscent64
Location: Texas
Contact:

Re: Tips for how to structure if statements when creating me

#5 Post by NocturneLight »

As far as I can figure, the wonky transform on the first go around isn't tied to xalign and yalign being used in the transform.

So, I made a new Ren'Py file and redid the window from scratch.

Code: Select all

define mc = Character("Clarevine Cole", color="#c8ffc8", who_outlines=[(1,"#4d0066")],what_outlines=[(1,"#4d0066")])


default spring_visible = None
default summer_visible = None
default scroll = None




transform make_visible:
    subpixel True
    xanchor 0.0 alpha 0.0
    
    parallel:
        easeout 1.0 xanchor 0.5 alpha 1.0
        
transform make_invisible:
    subpixel True
    xanchor 0.5 alpha 1.0
    
    parallel:
        easeout 1.0 xanchor 0.0 alpha 0.0
        
transform scroll_up:
    subpixel True
    yanchor 0.0
    
    parallel:
        easein 1.0 yanchor 0.5
        
transform scroll_down:
    subpixel True
    yanchor 0.5
    
    parallel:
        easein 1.0 yanchor 0.0


    
        
screen Test:
    modal True

    key "K_DOWN" action SetVariable("scroll", True)
    key "K_UP" action SetVariable("scroll", False)
    
    window:
        background "#000"
        area(0, 0, 1300, 750)
        
    vbox xalign 0.1 yalign 0.5:
        textbutton "Spring" action ToggleVariable("spring_visible", True, False), SetVariable("scroll", None), SetVariable("summer_visible", None)
        textbutton "Summer" action ToggleVariable("summer_visible", True, False), SetVariable("scroll", None), SetVariable("spring_visible", None)
        textbutton "Fall"
        textbutton "Winter"
    
    vbox xalign 0.3 yalign 0.5:
        if spring_visible:
            at make_visible
            textbutton "Spring 1"
            textbutton "Spring 2"
            textbutton "Spring 3"
            textbutton "Spring 4"
        elif spring_visible == False:
            at make_invisible
            textbutton "Spring 1"
            textbutton "Spring 2"
            textbutton "Spring 3"
            textbutton "Spring 4"
        elif summer_visible:
            at make_visible
            textbutton "Summer 1"
            textbutton "Summer 2"
            textbutton "Summer 3"
            textbutton "Summer 4"
        elif summer_visible == False:    
            at make_invisible
            textbutton "Summer 1"
            textbutton "Summer 2"
            textbutton "Summer 3"
            textbutton "Summer 4"
        
        if scroll:
            at scroll_up
        elif scroll == False:
            at scroll_down
            
        

label start:
    show screen Test
    mc "Boomshakalaka."


When I redid the entire thing, everything worked fine besides the part where you're able to press up when you shouldn't be able to press up or where you're able to press down when you shouldn't be able to press down.

From what I can tell, if I can find a way to tell which transform triggered before scroll was set to None and depending on the transform, only allow certain keys to be able to be pressed, I might be able to solve the problem.


The question is, is that even possible?
The Old Guard is at His Limit. The time is near to usher in the New Guard.

The Great Horror is soon to be free.

Clarevine is the key.


"Unsound Minds: The Clarevine Epoch" is a yuri visual novel that shatters english visual novel norms and aims to blend Christianity and the Cthulhu Mythos to tell a deep and dark story that you'll enjoy. You can follow the Kickstarter here.

Stay sound and persist through the chaos,
NocturneLight

Post Reply

Who is online

Users browsing this forum: Google [Bot], piinkpuddiin