Question: Testing Variable Against Multiple Others?

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
Kayotime
Regular
Posts: 37
Joined: Thu Jan 26, 2017 4:12 pm
Projects: Shinpaku High, Sakura Sunset
Location: America (US)
Contact:

Question: Testing Variable Against Multiple Others?

#1 Post by Kayotime »

Hi! Me again. I ran into yet another problem! Argh! Anyway, this one is pretty simple, I think. The answer is probably right under my nose!

Here's the code:

Code: Select all

label result:
    
    if O > A:
        if O > B:
            if O > AB:
                $ blood = "O"
                jump quizend
    elif A > O:
        if A > B:
            if A > AB:
                $ blood = "A"
                jump quizend
    elif B > O:
        if B > A:
            if B > AB:
                $ blood = "B"
                jump quizend
    elif AB > O:
        if AB > A:
            if AB > B:
                $ blood = "AB"
                jump quizend
    elif O == A or O = B or O = AB or A == B or A == AB or B == AB: ## It's this part that's the problem.
        na "Hmmm.... maybe one more question is in order..."
        menu:
            "Which of these letters do you like the most?"
            "A":
                $ blood = "A"
                jump quizend
            "B":
                $ blood = "B"
                jump quizend
            "O":
                $ blood = "O"
                jump quizend
            "Both A and B":
                $ blood = "AB"
                jump quizend
I'm trying to get the player's blood type to be set to a certain value based on how many points that variable got in the short quiz (not shown). So if the player took the quiz and got a score of 2 in 'O' and 2 in 'A', then 'O' variable would equal 2 and the 'A' variable would equal 2. The blood type should be set to whatever relevant variable got the highest score, but in events of a tie, for now I want a simple way to decide the type. I'll make it a bit more complex and story-friendly later, but right now for the purposes of testing the script and putting out a long-delayed Build, I just want this simple tiebreaker.

However, every time I get to that part in testing, I get an error. I've included the traceback.txt for reference.

PLEASE HELP!
Attachments
traceback.txt
The traceback for the error.
(874 Bytes) Downloaded 86 times
Active Project: Sakura Sunset
NOTICE: Shinpaku High is being put on hold for now. Sorry for the inconvenience!
Thank You!

User avatar
SuperbowserX
Veteran
Posts: 270
Joined: Sat Jan 07, 2017 3:09 pm
Contact:

Re: Question: Testing Variable Against Multiple Others?

#2 Post by SuperbowserX »

Just some points. You can simplify code conditionals using "and". For instance:

Code: Select all

if (a > b):
    if (a > b2):
        "A is bigger than B."
is the same thing as:

Code: Select all

if ((a > b) and (a > b2)):
    "A is bigger than B."
https://www.programiz.com/python-programming/operators

So you can simplify and shorten your code a lot here. Also, if you want to see if at least one condition is true, you can use "or" instead of "and"

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

Re: Question: Testing Variable Against Multiple Others?

#3 Post by Ocelot »

First suggestion: if last condition should always fire if previous were not true, get rid of that condition completely and use an 'else'. You can leave a comment, that it should work, if there is a tie.

Second: nested if statements are actually wrong in your case. Look for yourself: if O is larger, than A, but smaller, than B, then:
1) O > A is checked. It evaluates to True, after that, outer if/elif chain is considered handled and nothing else would be checked. It already selected a branch.
2) Inside chosen branch next condition is encountered. O > B is checked and evaluated to False. Conditional block is skipped.
3) Chosen branch ends. Control is given to statement following last elif block (just past the code you posted). No other conditions are checked.
You must either move all conditions in outer ifs, or check for tie first, and then, if there is no tie, check for a winner.

A way to do this with slightly more complex Python code.

Code: Select all

# We will use (value, value_name) tuples to make use of tuple natural ordering.
$ values = sorted([ (O, 'O'), (A, 'A'), (B, 'B'), (AB, 'AB') ])
if values[0][0] != values[1][0]: # if there is no tie
    $ blood = values[0][1] # set blood to value_name of blood with highest value
else:
    pass
    # Do your questions here
< < insert Rick Cook quote here > >

User avatar
Kayotime
Regular
Posts: 37
Joined: Thu Jan 26, 2017 4:12 pm
Projects: Shinpaku High, Sakura Sunset
Location: America (US)
Contact:

Re: Question: Testing Variable Against Multiple Others?

#4 Post by Kayotime »

Okay, so before I put in that code and test it, I want to confirm that what I got out of this is correct:

Code: Select all

## I should use the 'and' statement instead, so:

label result:    ## If there is NOT a tie, these should determine the result.
    if ((O > A) and (O > B) and (O > AB)):
        $ blood = "O"
        jump quizend
    elif ((A > O) and (A > B) and (A > AB)):
        $ blood = "A"
        jump quizend
    elif ((B > O) and (B > A) and (B > AB)):
        $ blood = "B"
        jump quizend
    elif ((AB > O) and (AB > A) and (AB > B)):
        $ blood = "AB"
        jump quizend

## Then I should replace the final 'elif' and use 'else', right?

    else:    ## If there IS a tie, the game will ask another set of questions to determine the winner.
        "Hmm... maybe another question is in order..."
        menu:
            "Which of these letters do you like best?"
            "A":
                $ blood = "A"
                jump quizend
            "B":
                $ blood = "B"
                jump quizend
            "O":
                $ blood = "O"
                jump quizend
            "Both A and B":
                $ blood = "AB"
                jump quizend

label quizend:

    ## Game continues here.
Is this right? I want to be sure I've got it down before I put it into my game.
Active Project: Sakura Sunset
NOTICE: Shinpaku High is being put on hold for now. Sorry for the inconvenience!
Thank You!

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

Re: Question: Testing Variable Against Multiple Others?

#5 Post by Ocelot »

Yes, looks right.
< < insert Rick Cook quote here > >

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Question: Testing Variable Against Multiple Others?

#6 Post by ISAWHIM »

If I may suggest... Instead of a comparison like this...

Since you are saying "Blood"...

I assume A=A, B=B, AB=AB, O=O (Missing the - and + variations by they way.)

However, the point of O is that it is compatible with all blood-types. Thus, dominates in equality, against others.
See the "Red blood cell compatibility" and "Plasma compatibility" Section in the link below.
https://en.wikipedia.org/wiki/Blood_type

NOTE: Plasma infusion is opposite. AB is dominant for compatability. (But you don't have AB.)

Which is why I would suggest this, if only A, B, and O are your options...

Code: Select all

if O>=A and O>=B:
    #O is greater or equal to one/both
    #O=A=B, or (O>=A and O>=B) 
    #then it is O, because O dominates and is compatible with A and B
elif A>B:
    #A>(B&O)
    #then it is A, because it is greater than B and also O
elif B>A:
    #This check is only to confirm that A is NOT equal to B, which is the final assumption "else", below.
    #B>(A&O)
    #it is B, because it is greater than A and also O 
else:
    #No check needed, this is the only other isolated potential value, equality of A and B, which are both greater than O
    #(A=B) > O
    #A==B (Do a single bonus question as a tie-breaker) Setting one value as the winner
    #it is not O=A=B, which would also have been caught above, with O dominating
    #... OR... Create the type AB as a fourth solution, which is the recessive blood that is only compatible with itself

User avatar
Kayotime
Regular
Posts: 37
Joined: Thu Jan 26, 2017 4:12 pm
Projects: Shinpaku High, Sakura Sunset
Location: America (US)
Contact:

Re: Question: Testing Variable Against Multiple Others?

#7 Post by Kayotime »

@Ocelot: Okay thank you!

@ISAWHIM: No, I'm sorry, I forgot to mention that I'm NOT basing this off actual blood type domination or anything. I AM planning on adding the + and - types in the future, but this will be based off the quiz as well, and not off the actual science of it. You see, the blood type is only included in the game because of its importance in Japanese culture. The blood type is like the Japanese zodiac sign: it is supposed to provide a window into the person's personality. Therefore, the quiz to determine the player's blood type is more of a personality quiz that gives the player different choices and benefits/penalties based on the personality traits associated with the blood type. In the future, I may add traits for the player to choose from that further affect the gameplay, but some of those traits may only be available if the player's blood type is associated with it, or perhaps the trait will provide a greater bonus/penalty if it matches up with the player's blood type. I'm extremely sorry for not clearing this up, and I appreciate your attempt to help, but in all honesty it is not needed. Thank you anyway!

I'm going to try the code now, I'll let you guys know how it goes.
Active Project: Sakura Sunset
NOTICE: Shinpaku High is being put on hold for now. Sorry for the inconvenience!
Thank You!

User avatar
ISAWHIM
Veteran
Posts: 318
Joined: Sun Nov 06, 2016 5:34 pm
Contact:

Re: Question: Testing Variable Against Multiple Others?

#8 Post by ISAWHIM »

Got it...

But I don't understand the comment... "Not based off the science of it"... When, A, B, AB, O = science of it. (Didn't exist "in culture", until it was made-up by science. Has nothing to do with zodiac... Was a fictitious "belief" from a nut-job military leader in 1927's, and was based off "the science of blood". Surely to get his own family into war-jobs, or out of being used as cannon-fodder. Actually, it is the reverse of what you said. It determines your personality, your personality doesn't determine the blood-type.)

It was only a "thing" from 1927 to 1930... Unless you are talking about that other thing from the 70's from that other nut-job... The broadcaster/journalist, who was born in the 1927's era and toxified the world after his german "studies" of blood science, relating them to statistical "random" data that favored his research and funded his family.
https://en.wikipedia.org/wiki/Masahiko_Nomi

That actually, sort-of makes sense.

That is also on the same page.
Society and culture
Main article: Blood type personality theory
A popular belief in Japan is that a person's ABO blood type is predictive of their personality, character, and compatibility with others. This belief is also widespread in South Korea and Taiwan. Deriving from ideas of historical scientific racism, the theory reached Japan in a 1927 psychologist's report, and the militarist government of the time commissioned a study aimed at breeding better soldiers. The fad faded in the 1930s due to its lack of scientific basis and ultimately the discovery of DNA in the following decades which it later became clear had a vastly more complex and important role in both heredity generally and personality specifically. No evidence has been found to support the theory by scientists, but it was revived in the 1970s by Masahiko Nomi, a broadcaster with a background in law who had no scientific or medical background. Despite these facts, the myth still persists widely in Japanese and South Korean popular culture.
"The theory was imported from Nazi race ideologues and adopted by Japan's militarist government in the 1930s to breed better soldiers. The idea was scrapped years later and the craze faded."
http://www.foxnews.com/story/2009/02/02 ... ality.html

He essentially took the most common blood-type (his paying audience), and made them out to be "the best personality", by finding a "few" individuals with medical records with those specific attributes. Then wrote a book to sell, to make money, when he failed as a journalist. Simply writing about german research and applying it to the japanese. Though, in all his "tests" he was never once able to identify anyone's blood-type, based off this science that he borrowed from history. Had he been a scientist, or a doctor, or even a decent journalist, and not a fantasy-writer... I imagine he would have admitted defeat, instead of dragging his family into his fantasy. Even his son, who was damned to continue his research, has come to the realization that there is no relation. (But it still puts money in his pockets.)

https://www.human-abo.org/
The "english" "go here" page...
http://aboworld.wixsite.com/global-abo/about

Their own "contradiction"... character is not a "fixed thing"... (Essentially nullifying all their own research, within their own documentation. Something a scientist or medical doctor never does, but a journalist does. It's called back-tracking. You are good, and you are also evil, but sometimes neither, and sometimes both. Bibles do the same thing.)
http://aboworld.wixsite.com/global-abo/guid5

What he actually believes, and is fact, is stated there too...
Human being is a social animal. If the social state changed, it will give influence to each one’s action and way of thinking. Conversely, conclusion of each one’s action and way of thinking also give influence to a social trend. Society and human beings always interacts each other.
EG, blood-type has nothing to do with it. Your personality is simply "the way you choose to act, based off your influence by your peers". It is like a horoscope. Every personality can be any sign, and is every sign. That is called humanity. No individual has ever been "just a single sign". Would be a messed-up world if it was like that. (With over 90% of the world being A or O, then we are all the same personality anyways, yet, we aren't.)

But, in any event, glad you have a solution you are looking for.

Interesting read, by the way... His book. Can't wait to see your game, based off of "the science" of it. :)

Maybe you will find more ideas from the links above, to add to your story. I hope. There is a lot of good fiction there, to get ideas from. Even a few facts too!

User avatar
Kayotime
Regular
Posts: 37
Joined: Thu Jan 26, 2017 4:12 pm
Projects: Shinpaku High, Sakura Sunset
Location: America (US)
Contact:

Re: Question: Testing Variable Against Multiple Others?

#9 Post by Kayotime »

*epic facepalm*

"What we have here is a failure to communicate..."

I understand your point, but I fear you're severely misunderstanding me.

Let me say it in plain English:

The function and purpose of the player's blood type in this game IS NOT the same function and purpose of a person's blood type in real life. Therefore, the general "rules" that apply to blood types, such as dominant/recessive types, compatibility and so forth, are NOT taken into account in the game. The sole purpose of the blood type in the game is to affect the player's experience in menu choices, dialogue, and other story elements by giving the player's character it's own personality based off what Japanese culture sees the blood type as, that is, a basis for your personality, much like how the zodiac signs may or may not provide an insight into your personality. If you have blood type A, Japanese culture/theory suggests that you are more patient, reserved, earnest, and responsible, but also stubborn, tense, and obsessive. This does not necessarily mean you ARE all these things if your blood type is A, just like having your zodiac sign be Aries doesn't mean you're arrogant and charming. This is just the idea of what your personality MIGHT be like, according to years of study and, yes, some belief in the inner-being having some connection to the universe as a whole. Basically, for all intents and purposes of this game, the player takes a "personality" quiz to determine what kind of person they are, then the game essentially "guesses" what their blood type is based off that personality, and therefore sets the player's blood type to the appropriate type. It DOESN'T MATTER if the player's blood type matches their characters. It is just a feature that adds a small amount of replay value to the game, (since the player can retake the quiz every time they start a new game, to see what affects each blood type/personality has on the game) and also makes use of an interesting piece of Japanese culture that I wanted to include because the game is so heavily based on Japanese culture, being an anime style life/date sim where many Japanese terms and traditions are used, especially in the case of common anime archetypes, such as Yandere, Himedere, Dandere, Neko, Kitsune, Genki, Moe, Oniichan, Osananajimi, and others.

So again, I apologize for any misunderstanding, but I just want to make it clear that this game is not largely based on realism, and therefore does not apply the same "rules" and commonalities as real life.

If you're interested in finding out more about the theory/cultural belief that this feature of the game is based off of, you can find the information here
Active Project: Sakura Sunset
NOTICE: Shinpaku High is being put on hold for now. Sorry for the inconvenience!
Thank You!

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Question: Testing Variable Against Multiple Others?

#10 Post by xavimat »

I would add a suggestion that simplifies the code, It works the same than your (based on Ocelot's) code but uses the python function max() than can be useful:

Code: Select all

label result:    ## If there is NOT a tie, these should determine the result.
    if O > max(A, B, AB):
        $ blood = "O"
        jump quizend
    elif A > max(O, B, AB):
        $ blood = "A"
        jump quizend
    elif B > max(O, A, AB):
        $ blood = "B"
        jump quizend
    elif AB > max(O, A, B):
        $ blood = "AB"
        jump quizend

    else:
        # ... the code in case of a tie...
Maybe it improves readability.

Doc: https://docs.python.org/2/library/functions.html#max
Last edited by xavimat on Sun Mar 05, 2017 5:22 pm, edited 1 time in total.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
Kayotime
Regular
Posts: 37
Joined: Thu Jan 26, 2017 4:12 pm
Projects: Shinpaku High, Sakura Sunset
Location: America (US)
Contact:

Re: Question: Testing Variable Against Multiple Others?

#11 Post by Kayotime »

@xavimat: Thank you! Just so you guys know, the code that Ocelot helped me with DID work, but I'll try this one too to see if that makes things smoother and easier. Thanks to everyone for all the help! Be sure to check out the latest Debug Build for Shinpaku High (this game) in the WIP section! Literally just released it a few minutes ago. I'll be working on the next build right away, but please don't hesitate to leave a suggestion or comment on the progress!
Active Project: Sakura Sunset
NOTICE: Shinpaku High is being put on hold for now. Sorry for the inconvenience!
Thank You!

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Question: Testing Variable Against Multiple Others?

#12 Post by xavimat »

Kayotime wrote:@xavimat: Thank you! Just so you guys know, the code that Ocelot helped me with DID work, but I'll try this one too to see if that makes things smoother and easier.
You're welcome :D
The two codes do the same. Use the one that you feel more readable and elegant according to your "tastes". Think, for example, in your "future you" reading again this code to debug it or maybe to reuse it in other projects.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Post Reply

Who is online

Users browsing this forum: No registered users