Ren'Py If statement on screens

Yooshi

Mega-Chonker
Game Developer
Dec 11, 2017
250
1,060
Hi!


I've got a tiny issue with an if statement in screens.
There's a map with locations in my game that players can go to and I want some of them to be closed on weekends so I created a weekend variable that works perfectly, it sets itself on true whenever there's a weekend in-game.


Then I've got my imagebutton that stands for a location. Period stands for a time of day - 0 is morning, 2 is night. If condition works for day periods, the location is closed at night but somehow it doesn't work for weekend. I placed the weekend condition above the period ones to make sure this condition is checked first.

imagebutton:
if weekend:
action Jump("closed")
if period == 0 or period == 1:
action Jump("opened")
elif period == 2:
action Jump("closed")


Can someone tell me why it's not working?

Edit: nvm, fixed it
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,976
16,231
Code:
imagebutton:
    if weekend:
                action Jump("closed")
    if period == 0 or period == 1:
                action Jump("opened")
    elif period == 2:
                action Jump("closed")
Can someone tell me why it's not working?
For those who wonder, I guess that the problem came from the double use of if. During week end, in periods 0 and 1 the button had two action property.
Normally Ren'Py throw an error when it encounter two action properties for the same button, but here the if are masking them. Therefore when it's week end, the property is set to Jump( "closed" ) then, because it's period 0 or 1, it's set again, but this time to jump( "opened" ).

The correct syntax would have been:
Code:
imagebutton:
    if weekend:
                action Jump("closed")
    elif period == 0 or period == 1:
                action Jump("opened")
    elif period == 2:
                action Jump("closed")
or, better:
Code:
imagebutton:
    if weekend or period == 2:
                action Jump("closed")
    else:
                action Jump("opened")