Strange behaviour of if

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
hapciupalit
Regular
Posts: 56
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Strange behaviour of if

#1 Post by hapciupalit »

Hi there,
I've been struggling with some easy things for two hours and for the life of me, I can't find what I have done wrong. Maybe I'm just stupid. If one of you sees the error please tell me cuz I can't find it.

Code: Select all

label home_front:
    $currentLocation = "home_front"
    $tClockVal = 0
    if scheduleId == 1:
        if tClockVal == 1 or 7 or 13 or 19 or 20 or 21 or 25 or 26 or 28:
            $print ("I'm here", tClockVal)
            call screen home_front("", "_off")
        else:
            $print ("I should be here")
            if tClockVal == 4 or 5 or 11 or 16 or 17 or 23 or 29 or 35 or 41:
                call screen home_front("_car", "_on")
            else:
                call screen home_front("_car", "_off")
For some reason I go in the if instead the else and in that log I see "I'm here 0" so I don't understand why it wouldn't go in the else.

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: Strange behaviour of if

#2 Post by drKlauz »

Your conditions are wrong, use

Code: Select all

if tClockVal == 1 or tClockVal == 7 or ...:
or

Code: Select all

if tClockVal in [1,7,13,19,20,21,25,26,28]:
P.S.: reason why condition is wrong is:

Code: Select all

if tClockVal == 1 or 7:
works next way:
- check if tClockVal equal to 1
- if not then check if 7 is truthy, which is always
So your condition is actually

Code: Select all

if tClockVal == 1 or True:
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

hapciupalit
Regular
Posts: 56
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Re: Strange behaviour of if

#3 Post by hapciupalit »

drKlauz wrote: Wed Nov 11, 2020 7:17 am Your conditions are wrong, use

Code: Select all

if tClockVal == 1 or tClockVal == 7 or ...:
or

Code: Select all

if tClockVal in [1,7,13,19,20,21,25,26,28]:
P.S.: reason why condition is wrong is:

Code: Select all

if tClockVal == 1 or 7:
works next way:
- check if tClockVal equal to 1
- if not then check if 7 is truthy, which is always
So your condition is actually

Code: Select all

if tClockVal == 1 or True:
I understand now... Thank you very much.

Cheers!

Post Reply

Who is online

Users browsing this forum: Google [Bot], LittleRainySeasons