[SOLVED] Comparing Numbered Variables Against One Another?

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
PangoDango
Regular
Posts: 30
Joined: Thu Jul 17, 2014 2:28 pm
Projects: Lovely Little Thieves
Organization: PangoDango Games
Location: California
Contact:

[SOLVED] Comparing Numbered Variables Against One Another?

#1 Post by PangoDango »

Hey Ren'py programmers! This is probably a pretty simple code thing, but I haven't been able to figure it out. I'm finishing up the demo for my game and it's the last puzzle piece I need solved.

Basically, I need a specific event to happen in the game based on relationship points, but it's not based on "if [character] points > 10" or whatever, it's in comparison to the relationship points of the other romance options. This would be easy if there were two or three of them, but there are five people.

Is there a simple way to do this that doesn't involve "if [character a] points > [character b] points, elif [character a] points > [character c] points, elif [character a] points > [character d] points," etc.? Is there a way to just call for "character with highest value of points in group"?

Thanks, and lookin' forward to releasing this game! :mrgreen:
Last edited by PangoDango on Sun Aug 24, 2014 1:24 am, edited 3 times in total.

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Comparing Numbered Variables Against One Another Help?

#2 Post by Asceai »

Simplest way, to me, seems to be to get the maximum and compare against it

Code: Select all

$most_points = max(alice_points, bob_points, charlie_points)
if alice_points == most_points:
    jump alice_route
elif bob_points == most_points:
    jump bob_route
elif charlie_points == most_points:
    jump charlie_route

User avatar
PangoDango
Regular
Posts: 30
Joined: Thu Jul 17, 2014 2:28 pm
Projects: Lovely Little Thieves
Organization: PangoDango Games
Location: California
Contact:

Re: Comparing Numbered Variables Against One Another Help?

#3 Post by PangoDango »

Cool, I'll try that.

So, that brings up another quandary. I almost forgot to mention it. In the case of a tie, I want there to be a hierarchy of which character the game defaults to. Because a five-way tie is *technically* possible, coding tiebreaker events would be a nightmare, so I'll need to code a block for "if there's a tie, choose this person."

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Comparing Numbered Variables Against One Another Help?

#4 Post by Asceai »

The way the example I posted is written, Alice wins the tiebreaker, then Bob, then Charlie. Just put them in order like that.

User avatar
PangoDango
Regular
Posts: 30
Joined: Thu Jul 17, 2014 2:28 pm
Projects: Lovely Little Thieves
Organization: PangoDango Games
Location: California
Contact:

Re: Comparing Numbered Variables Against One Another Help?

#5 Post by PangoDango »

Asceai wrote:The way the example I posted is written, Alice wins the tiebreaker, then Bob, then Charlie. Just put them in order like that.
Oh, thank you! That's extremely helpful. :D I figured the answer was probably simple! I just don't know much about coding. It's been an adventure trying to learn for this game. :lol:

Post Reply

Who is online

Users browsing this forum: No registered users