[solved!!!]Having trouble understanding how to use multiple conditions

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
skyeworks
Regular
Posts: 84
Joined: Thu Jul 27, 2017 11:36 am
Projects: K9-11
itch: skyefrost
Contact:

[solved!!!]Having trouble understanding how to use multiple conditions

#1 Post by skyeworks »

So I've been trying to put a condition statement. And what happens is that the game would only see the first if and not the second one. I don't know what's I'm doing wrong and the documentation was not very easy to understand.

Code: Select all

    scene lexp_up
    if AL == 100:
        play sound "jivatma07__level-up-3note2.mp3"
        "Level 2"
        $ AL = 0 
        $ Lvl2 = True
        jump pub
        
    elif Lvl2 == "True" and AL == 100:
        play sound "jivatma07__level-up-3note2.mp3"
        "Level 3!"
        $ AL = 0 
        $ Lvl3 = True
        jump pub
  
   else: 
  	jump pub
Last edited by skyeworks on Mon Sep 03, 2018 8:49 pm, edited 1 time in total.
Image

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Having trouble understanding how to use multiple conditions

#2 Post by philat »

If AL is 100, you never reach the second evaluation because the first condition block runs. You need to put the most restrictive condition first.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Having trouble understanding how to use multiple conditions

#3 Post by trooper6 »

So remember that the computer is going to go in order through that conditional list and do the first one that is relevant and then stop.

So let's say AL == 100. What happens?
The computer looks at the first conditional and asks, is AL == 100? The answer is yes, so it does that first block. It plays the sound, says "Level 2," AL goe to 0 and Lvl2 becomes Then, then we jump to pub.

So...now we get another 100 AL and check again. What happens?
The computer looks at the first conditional and asks, is AL==100? The answer is yes, so it does that first block. It plays the sound, says "Level 2," AL goe to 0 and Lvl2 becomes Then, then we jump to pub.

We are never going to get to the second conditional because the first conditional is always true.

So you have to rewrite the whole conditional chain.

Try something like this:

Code: Select all

default level = 1

label levelup(): 
    if AL==100:
        play sound "jivatma07__level-up-3note2.mp3"
        $AL=0
        if level == 1:
            $level+=1
            "Level 2"
        elif level == 2:
            $level+=1
            "Level 3"
        else:
            "You've reached max level!"
        jump pub
    else:
        jump pub
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
skyeworks
Regular
Posts: 84
Joined: Thu Jul 27, 2017 11:36 am
Projects: K9-11
itch: skyefrost
Contact:

Re: Having trouble understanding how to use multiple conditions

#4 Post by skyeworks »

omg! Thank you! that's what I needed to do! Thank you, to the both of you for explaining it!
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]