# Is there any way to code it so the game checks a series of stats for the lowest one?

Is it possible to code it so choicescript checks a series of variable stats and select the lowest one at that point?

For example

[Let’s say the game features five people]

[PLAYER]
[NPC1]
[NPC2]
[NPC3]
[NPC4]

[the game features a challenge in each scene where their is 100 available points which is shared out on performance. After the first challenge the scores are…]

[PLAYER] = 25
[NPC1] = 50
[NPC2] = 20
[NPC3] = 5
[NPC4] = 0

[after each round the person with the lowest score is eliminated. So in this case NPC4 would be out and the next challenge would feature…]

[PLAYER]
[NPC1]
[NPC2]
[NPC3]

[If the game always ended with the same person having the lowest score it’d be easy to code. But let’s say the score actually could end up differently…]

game one
[PLAYER] = 25
[NPC1] =25
[NPC2] =15
[NPC3] = 5
[NPC4] = 30

game two
[PLAYER] = 50
[NPC1] =10
[NPC2] =10
[NPC3] = 25
[NPC4] = 5

game three
[PLAYER] = 60
[NPC1] = 0
[NPC2] =5
[NPC3] = 20
[NPC4] = 15

[As you can see each game can have a different character have the lowest score. Is there any way of coding it so the game would remove who ever had the lowest score each time the results happen? This is just an example of what i mean its not part of any game.]

I think you need to compare them using if statements. I’m sure someone will come along with a better solution.

`*if (NPC1<NPC2) and (NPC1<NPC3) and (NPC1<NPC4) and (NPC1<Player) *set 1eliminated NPC1 *goto eliminated *if (NPC2<NPC1) and (NPC2<NPC3) and (NPC2<NPC4) and (NPC2<Player) *set 1eliminated NPC2 *goto eliminated *if (NPC3<NPC1) and (NPC3<NPC2) and (NPC3<NPC4) and (NPC3<Player) *set 1eliminated NPC3 *goto eliminated *if (NPC4<NPC2) and (NPC4<NPC2) and (NPC4<NPC3) and (NPC4<Player) *set 1eliminated NPC4 *goto eliminated *if (player<NPC1) and and (player<NPC2) (player<NPC3) and (player<NPC4) *set 1eliminated player *goto player_eliminated`

Then for the second elimination I’d check

`*if 1eliminated=!NPC1 *if (npc1<npc2) blah blah blah`

But now I have problems since for the second elimination, it’s comparing it to someone who’s been eliminated. So I’d likely set each person, as they’re eliminated up to an impossible high score so set them up to 9999 once they’re eliminated (but that may mess up your scoreboard). There’s undoubtedly a better way to do it.

@FairyGodfeather

Yeah thats how I was going to do it but wondered if there was an easier way.

I’m sure someone like @CJW will swoop in and let you know. My own code tends to be very clumsy and I don’t know all of the cool commands.

Why not create 5 true/false variables to record when a player is in the game? Just run a check of their scores after every scene, and if a player’s score is below a set threshold you set the value to false. Then you can use *goto to reach a specific scene where they are eliminated and move on.

This way, you can keep track of every player who is still in the game through a series of questions. You just have to make the scenes less specific.

What’s best I think would depend on the length of your list. For a small list I’d probably go with something like:

``````
*set low "NPC1"
*if (NPC2 < {low})
*set low "NPC2"
*if (NPC3 < {low})
*set low "NPC3"
*if (NPC4 < {low})
*set low "NPC4"
*if (player < {low})
*set low "player"

\${low} has been eliminated with a stat of
*print {low}
.

``````

Note that a “referenced” value can’t be printed directly without an explicit *print statement. ( @dfabulich, do you think we can get the ability to do it added to Choicescript? ) Otherwise you’d have to create a variable just so you can print it without the *print statement as was done in the advanced choicescript guide.

For a longer list, or to use the same code to handle multiple elimination rounds, I’d add a counting variable, a second new variable for the current character being compared, and iterate through a loop using *goto. Recursion via *gosub would also work well for a longer list.

1 Like

@P_Tigras

That’d be perfect!

Thank you