comparing multiple values and adding more 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
gooksunim
Newbie
Posts: 3
Joined: Thu Dec 30, 2021 10:45 am
Contact:

comparing multiple values and adding more conditions

#1 Post by gooksunim »

I have 7 values, A, B, C, D, E, F, G

If A is the highest number (but can be same number) with B, C, D, E, F, G;
and if another value proportional to the number A is over 700,
the story will lead to choice 1,
if B is the highest number (but can be same number) with A, C, D, E, F, G;
and if another value proportional to the number B is over 700,
the story will lead to choice 2,

and so on... was what I was planning to do.


Code: Select all

label end_eval:

    if money >= 4000:
        $ choice = 0

    else:
        jump end_eval1

label end_eval1:

    if A >= B and A >= C and A >= D and A >= E and A >= F and A >= G:
        if strength >= 700:
            $ choice = 1

    else:
        jump end_eval2

label end_eval2:

    if B >= A and B >= C and B >= D and B >= E and B >= F and B >= G:
        if knowledge >= 700:
            $ choice = 2
    else:
        jump end_eval3

label end_eval3:

    if C >= A and C >= B and C >= D and C >= E and C >= F and C >= G:
        if kindness >= 700:
            $ choice = 3
    else:
        jump end_eval4

label end_eval4:

    if D >= A and D >= B and D >= C and D >= E and D >= F and D >= G:
        if 250 <= magic < 1000:
            $ choice = 4
        elif magic >= 1000:
            $ choice = 5
    else:
        jump end_eval5

label end_eval5:

    if E >= A and E >= B and E >= C and E >= D and E >= F and E >= G:
        if knowledge >= 500:
            $ choice = 6
    else:
        jump end_eval6

label end_eval6:

    if F >= A and F >= B and F >= C and F >= D and F >= E and F >= G:
        if strength >= 500:
            $ choice = 7
    else:
        jump end_eval7

label end_eval7:

    if G >= A and G >= B and G >= C and G >= D and G >= E and G >= F:
        if kindness >= 500:
            $ choice = 8
    else:
        $ choice = 9
I hoped this would work, but it does not. It ends up in choice 9. Can someone please help me? Thank you.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2397
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: comparing multiple values and adding more conditions

#2 Post by Ocelot »

Lets check what happens when F is the highest number:
1) if F >= A ... condition is checked and is true, strenght is over 500, so choice choice is set to 7
2) else block is skipped, since condition was true.
3) Next line is label end_eval7: this is technical statement, it does nothing during execution.
4) if G >= A ... condition is checked and it is false
5) since previous condition was false, else block is executed. THis will set choice to 9
6) choice is 9!

Interestingly enough, code should work properly if G is the largest value.
< < insert Rick Cook quote here > >

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: comparing multiple values and adding more conditions

#3 Post by Alex »

gooksunim wrote: Sat Jan 15, 2022 5:25 pm I have 7 values, A, B, C, D, E, F, G...
This might help - https://patreon.renpy.org/picking-a-winner.html
(the other useful articles - viewtopic.php?f=51&t=47328)

Post Reply

Who is online

Users browsing this forum: Google [Bot]