How to do Comparisons Between Variables?
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.
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.
- EusthEnoptEron
- Newbie
- Posts: 21
- Joined: Thu Jul 10, 2008 6:27 am
- Location: Switzerland
- Contact:
Re: How to do Comparisons Between Variables?
You could use the .reverse() method of the List object after you've sorted it, I guess.
Real programmers don't comment their code - it was hard to write, it should be hard to understand.
- PyTom
- Ren'Py Creator
- Posts: 15893
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: How to do Comparisons Between Variables?
You want to do:
jump expression scores[-1][1]
The -1 refers to the last item in the scores list. Sorry about forgetting this in my original post... about 90% of the time when I sort, I want the smallest rather than the largest number.
jump expression scores[-1][1]
The -1 refers to the last item in the scores list. Sorry about forgetting this in my original post... about 90% of the time when I sort, I want the smallest rather than the largest number.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom
- cloverfirefly
- Newbie
- Posts: 22
- Joined: Wed Jun 25, 2008 1:59 am
- Completed: The Curious Alliance
- Contact:
Re: How to do Comparisons Between Variables?
Thanks, PyTom. Problem solved.
For anyone following along, here is the fixed version of the sample game I posted earlier.
For anyone following along, here is the fixed version of the sample game I posted earlier.
Code: Select all
label start:
$ mary_score = 2
$ eileen_score = 1
$ lucy_score = 3
"Eileen's score is %(eileen_score)s."
"Lucy's score is %(lucy_score)s."
"Mary's score is %(mary_score)s."
python:
scores = [
(eileen_score, "eileen_ending"),
(lucy_score, "lucy_ending"),
(mary_score, "mary_ending"),
]
scores.sort()
jump expression scores[-1][1]
label eileen_ending:
"Eileen likes you the most!"
return
label lucy_ending:
"Lucy likes you the most!"
return
label mary_ending:
"Mary likes you the most!"
return
-
Watercolorheart
- Eileen-Class Veteran
- Posts: 1314
- Joined: Mon Sep 19, 2005 2:15 am
- Completed: Controlled Chaos / Sum of the Parts / "that" Midna game with ZONEsama
- Projects: Sparse Series/Oddments Shop original cartoon in Pevrea; Cybernetic Duels (fighting game); Good Vibin'
- Organization: Watercolorheart Studios
- IRC Nick: BCS
- Tumblr: adminwatercolor
- Deviantart: itsmywatercolorheart
- Github: Watercolordevdev
- Skype: heartnotes
- Soundcloud: Watercollider
- itch: watercolorheart
- Location: Florida
- Contact:
Re: How to do Comparisons Between Variables?
What does this part do
scores = [
(eileen_score, "eileen_ending"),
(lucy_score, "lucy_ending"),
(mary_score, "mary_ending"),
]
Is it connecting the name of the variable to the jump?
scores = [
(eileen_score, "eileen_ending"),
(lucy_score, "lucy_ending"),
(mary_score, "mary_ending"),
]
Is it connecting the name of the variable to the jump?
I'm not even the same person anymore
- PyTom
- Ren'Py Creator
- Posts: 15893
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: How to do Comparisons Between Variables?
It's actually connecting the value of the variable to the jump. Basically, what we do is:
1) Create a list of score-label pairs.
2) Sort that list.
3) Jump to the label of the last thing in the list, which is the one with the highest score.
Being able to do this sort of thing is why it's important to include a full-fledged programming language as part of your visual novel engine. While you could do this for a few labels with simple compare-jumps, that can become unwieldy fast, while this approach scales easily.
1) Create a list of score-label pairs.
2) Sort that list.
3) Jump to the label of the last thing in the list, which is the one with the highest score.
Being able to do this sort of thing is why it's important to include a full-fledged programming language as part of your visual novel engine. While you could do this for a few labels with simple compare-jumps, that can become unwieldy fast, while this approach scales easily.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom
Re: How to do Comparisons Between Variables?
This list uses tuples to connect the scores to the ending to call if that score wins. The winning score is determined by sorting the list which orders it by score, with the highest score being at the end of the list. A list like this works well when there are a lot of characters.BCS wrote:What does this part do![]()
scores = [
(eileen_score, "eileen_ending"),
(lucy_score, "lucy_ending"),
(mary_score, "mary_ending"),
]
Is it connecting the name of the variable to the jump?
Who is online
Users browsing this forum: Bing [Bot], _ticlock_

