Hi All,
I’m trying to add a passage that keeps track of a variable and sorts that variable Highest to lowest in the form of a chart.
In the example below I’ve used Name and Score.
The somewhat clunky code I’ve got works but has no provision for if 2 players have the same score and I think will be unworkable for a larger amount of players.
Ideally I want a list of 10 ordered High to Low.
Is there a better way to do what I’m doing?
Many many thanks!!
Twine Version: 2.35
Story Format: Harlowe 3.1.0
{
(set: $PLAYER_A to (datamap:
"name", "Rod",
"score", 10))
(set: $PLAYER_B to (datamap:
"name", "Jane",
"score", 20))
(set: $PLAYER_C to (datamap:
"name", "Freddy",
"score", 30))
<!--PLAYER A-->
(if: $PLAYER_A's score > $PLAYER_B's score and > $PLAYER_C's score)[(set: $Number1 to $PLAYER_A's name)]
(if: $PLAYER_A's score < $PLAYER_B's score and > $PLAYER_C's score)[(set: $Number2 to $PLAYER_A's name)]
(if: $PLAYER_A's score > $PLAYER_B's score and < $PLAYER_C's score)[(set: $Number2 to $PLAYER_A's name)]
(if: $PLAYER_A's score < $PLAYER_B's score and < $PLAYER_C's score)[(set: $Number3 to $PLAYER_A's name)]
<!--PLAYER_B-->
(if: $PLAYER_B's score > $PLAYER_A's score and > $PLAYER_C's score)[(set: $Number1 to $PLAYER_B's name)]
(if: $PLAYER_B's score < $PLAYER_A's score and > $PLAYER_C's score)[(set: $Number2 to $PLAYER_B's name)]
(if: $PLAYER_B's score > $PLAYER_A's score and < $PLAYER_C's score)[(set: $Number2 to $PLAYER_B's name)]
(if: $PLAYER_B's score < $PLAYER_A's score and < $PLAYER_C's score)[(set: $Number3 to $PLAYER_B's name)]
<!--PLAYER_C-->
(if: $PLAYER_C's score > $PLAYER_A's score and > $PLAYER_B's score)[(set: $Number1 to $PLAYER_C's name)]
(if: $PLAYER_C's score < $PLAYER_A's score and > $PLAYER_B's score)[(set: $Number2 to $PLAYER_C's name)]
(if: $PLAYER_C's score > $PLAYER_A's score and < $PLAYER_B's score)[(set: $Number2 to $PLAYER_C's name)]
(if: $PLAYER_C's score < $PLAYER_A's score and < $PLAYER_B's score)[(set: $Number3 to $PLAYER_C's name)]
Hi-score chart
<br>
<br>1. (print: $Number1)
<br>2. (print: $Number2)
<br>3. (print: $Number3)
}