Finding the Highest Value of Variables for Endings

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
Yappano
Newbie
Posts: 3
Joined: Sat Nov 17, 2012 10:29 pm
Location: Japan
Contact:

Finding the Highest Value of Variables for Endings

#1 Post by Yappano »

Hello,

I'm making a short concept game following one character. You can get three endings depending on your conversations. With your choices, you can either increase the value of his love, friendship, or anger.

To do this, I have been using $. For example: $ anger += 1

For the ending, I want to have whichever of the three variables is the highest to lead to an ending. However, I'm not sure how to make Ren'Py find that value.

I was first going to just make if else statements because I understand those for the most part, but that doesn't seem to fit.

On top of the above, I'd also like to know what I should do if after Ren'Py finds the highest variable, there is a tie. Would it error out if that happened?

Thank you very much!

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

Re: Finding the Highest Value of Variables for Endings

#2 Post by philat »

There's a more conceptual question here (for instance, how are you going to do tiebreakers? It's not so much a question of errors as you just have to decide what happens if there is one), but if statements should be fine for the mechanics. There are only three possible outcomes anyway.

Code: Select all

if a > b and a > c:
   "a is larger than both b and c"
elif b > a and b > c:
   "b is larger than both a and c"
elif c > a and c > b:
   "c is larger than both a and b"
else:
   "something went wrong"

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

Re: Finding the Highest Value of Variables for Endings

#3 Post by xavimat »

First, you need to decide what ending has priority in case of a tie. Say if all three variables have the same value, what ending should renpy choose?
(OR you could write 7 endings, because there are seven possibilities counting ties and no-ties, but let's stick to your three endings).

For example, you want it hard for the player, and, in case of a tie, you choose the worst option, so the order of priority is: anger, friendship, love. The code could be:

Code: Select all

if anger >= max(friendship, love):
    jump anger_ending
elif friendship >= love:
    jump friendship_ending
else:
    jump love_ending
The trick is in the >= part.
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
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Finding the Highest Value of Variables for Endings

#4 Post by Alex »

Yappano wrote: Tue Feb 19, 2019 12:50 am ...
Also, check PyTom's article - https://patreon.renpy.org/picking-a-winner.html

User avatar
Yappano
Newbie
Posts: 3
Joined: Sat Nov 17, 2012 10:29 pm
Location: Japan
Contact:

Re: Finding the Highest Value of Variables for Endings

#5 Post by Yappano »

THANK YOU SO MUCH, YOU GUYS. You explained it very well.

And thank you for the link! I definitely have a lot of reading to do as I continue to work and find new problems.

Have a great day~!

Post Reply

Who is online

Users browsing this forum: Andredron, Bing [Bot], mold.FF