# Stat checking multiple vars

Is there a way to run a stat check on multiple var’s to determine which out of said vars has the highest percent?

What I have so far is this, but I think I am going about this the wrong way.

``````*if ((((charm  > genuine ) and (charm  > friendly ) and (charm > outgoing ) and (charm  > emotional ))))
``````

There is probably a more elegant way to do this, but I can’t think of it.

My only advice is, if this is a type of check you’re going to do more than once, it might make sense to create a subroutine and a seperate variable tracking the highest stat.

So create, e.g., `high_stat = "charm"`

and a subroutine along the lines of what you have already:

``````*label high_stat_check
*if ((((charm  > genuine ) and (charm  > friendly ) and (charm > outgoing ) and (charm  > emotional ))))
*set high_stat = "charm"
*return
*elseif (((genuine > charm) and (genuine > friendly ) and (genuine > outgoing ) and (genuine > emotional ))))
*set high_stat = "genuine"
*return
``````

and so on (you’ll also have to deal with ties!).

And then when you want to run the test, you can just do, e.g.,

``````*gosub high_stat_check
*if high_stat = "charm"
charming blah
*elseif high_stat = "genuine"
genuine blah
``````

etc.

Ed: this thread has a few alternates (like what @sviyagin just posted below )

2 Likes

I think this would be the most efficient way to do it

``````*create highest_stat

*set highest_stat_name "charm"
*set highest_stat charm
*if (genuine > highest_stat)
*set highest_stat_name "genuine"
*set highest_stat genuine
*if (friendly > highest_stat)
*set highest_stat_name "friendly")
*set highest_stat friendly
*if (outgoing > highest_stat)
*set highest_stat_name "outgoing"
*set highest_stat outgoing
*if (emotional > highest_stat)
*set highest_stat_name "emotional"'
*set highest_stat emotional
*return
``````

I know it’s not a multi-variable *if statement, but as a gosub routine, you can employ it anytime you want. The subroutine will shuffle through every stat you have and the end result will be whichever stat is the highest. You can add as many variables to this as you want, and I’ve used this kind of code before

EDIT: you need two lines, one to name your variable (that’s the ones with the “”) and one to set the value of highest_stat (that’s the one without the “”)–that’s because the code needs a value to check highest_stat against

2 Likes

Wow, just gave it a quick run and yup that pretty much covers it thanks @sviyagin and @Gabs!

3 Likes

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the @moderators.