# Counting variables

#1

I was wondering if there’s a way to calculate what the highest stat is among a player’s attributes. For example, if their available stats are:
-strength: 3
-agility: 2
-stealth: 1
Is there a way to work out and track which stat is the highest?

#2

I’ve actually been wondering about this, too. I wanted to have this personality quiz-like feature in one of my games and really there’s no way to find the highest valued variable besides creating a ton of conditionals.

#3

You have to just run down the list, checking each one, the quickest and easiest I think would be something like:

``````*temp highest_stat
*set highest_stat "strength"
*if agility > {highest_stat}
*set highest_stat "agility"
*if stealth > {highest_stat}
*set highest_stat "stealth"
Your \${highest_stat} is your highest stat, at \${{highest_stat}}.
``````

Note that will favor anything at the top of the list, so if agility is 3 and strength is 3, it will return agility. If you want to check if anything is equal to the highest stat, you’ll need a few more checks. (also note you’re going to need the newest update to copy/paste the above code).

How to use the highest stat
#4

That’s a LOT neater than what I’ve been doing, lol! My only issue is what would happen in the case of ties. I guess it would be possible to just have the highest stat randomized in that case.

#5

Thanks, that seems like a less strenous set of checks than what I was planning on doing. There’s no check for “greater or equal to” in CS is there?

#6

There is (>= and <=), but with the structure @Reaperoa used I don’t think it’s necessary.

#7

Sure is!

``````*if (highest_stat >= other_stat)
``````

will compile just fine.

If you swap all of @Reaperoa’s examples to use >=, then you’ll favor the stat on the bottom of the list instead of the stat at the top.

(Aww, ninjaed by @seabean.)

#8

@seabean In handling ties, it depends on how you’re counting, and what you’re using the numbers for. If you’re using fairmath, it’s probably permissible to just have the stats favored in a list, while if you’re using small counters, it’s probably going to be more likely you’ll want to make concessions for equal numbers.

#9

Thanks so much! I kinda see how I can do what I’m planning now