# Min-Max command

**URL:** <https://forum.choiceofgames.com/t/min-max-command/32646>\
**Category:** ChoiceScript Help\
**Created:** [November 25, 2017, 4:18pm UTC](https://forum.choiceofgames.com/t/min-max-command/32646 "2017-11-25T16:18:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoldenSilver](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/goldensilver/32/110153_2.png) [@GoldenSilver](https://forum.choiceofgames.com/u/GoldenSilver)\
**Post date:** [November 25, 2017, 4:18pm UTC](https://forum.choiceofgames.com/t/min-max-command/32646/1 "2017-11-25T16:18:52Z")

</div>

Hi, I’m just curious if there is a way to compare number variables and find the smallest and highest one, like some sort of min max command?

I want the game to analyze the player’s morality for something, selecting the highest or lowest opposed\_pair so I can set some sort of title for the player. Is there a better way to do this than a bunch of \*if commands?

Sort of like Math.min and Math.max in Java.

---

<div class="post-metadata">

**Author:** ![Gower](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/gower/32/21972_2.png) [@Gower](https://forum.choiceofgames.com/u/Gower)\
**Post date:** [November 25, 2017, 4:46pm UTC](https://forum.choiceofgames.com/t/min-max-command/32646/2 "2017-11-25T16:46:00Z")

</div>

I’m afraid I don’t know a simple way to do that. Here’s the code I use to determine the highest stat for a number of stats (bold; culture; intellect; skullduggery; observe; persuade). Perhaps you can tweak it to serve your needs. It will return the highest stat for “mainstat” and the value of the highest stat for “mainstatval”

```
*label mainstat_check

*set mainstat "bold"
*set mainstatval bold
*if culture > mainstatval
	*set mainstat "culture"
	*set mainstatval culture
*if intellect > mainstatval
	*set mainstat "intellect"
	*set mainstatval intellect
*if skullduggery > mainstatval
	*set mainstat "skullduggery"
	*set mainstatval skullduggery
*if observe > mainstatval
	*set mainstat "observe"
	*set mainstatval observe
*if persuade > mainstatval
	*set mainstat "persuade"
	*set mainstatval persuade

*return
```

---

<div class="post-metadata">

**Author:** ![GoldenSilver](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/goldensilver/32/110153_2.png) [@GoldenSilver](https://forum.choiceofgames.com/u/GoldenSilver)\
**Post date:** [November 25, 2017, 6:30pm UTC](https://forum.choiceofgames.com/t/min-max-command/32646/3 "2017-11-25T18:30:05Z")

</div>

Thanks for the answer, I’ll only try this later though, but I’ll use this little script. Was thinking of just a bunch of \*ifs and \*elseifs, needless to say, it was a nightmare. This one seems very manageable.

Also does this cover if the stat is low? Like for example this is for morality meters. Such as greed, that is generous on the low scale and greedy on the highest scale, but I want to get the stat that the player min or maxed the most. Like if he was most compassionate, or most greedy etc

---

<div class="post-metadata">

**Author:** ![Gower](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/gower/32/21972_2.png) [@Gower](https://forum.choiceofgames.com/u/Gower)\
**Post date:** [November 25, 2017, 6:42pm UTC](https://forum.choiceofgames.com/t/min-max-command/32646/4 "2017-11-25T18:42:24Z")

</div>

For bipolar stats you can do this:

If you have miserly/generous you can

\*create miserly  
\*set miserly (100 - generous)

Then you can just plug in miserly along with the other variables.

---

<div class="post-metadata">

**Author:** ![Alexandra](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/alexandra/32/59402_2.png) [@Alexandra](https://forum.choiceofgames.com/u/Alexandra)\
**Post date:** [November 25, 2017, 8:39pm UTC](https://forum.choiceofgames.com/t/min-max-command/32646/5 "2017-11-25T20:39:03Z")

</div>

I’m planning to do something similar and still haven’t figured out an ideal way to do this – @Gower’s solution doesn’t have a clear way to deal with ties, for example (the stats listed first will ‘win’ ties unless you write code to check for it). You might find the other suggestions on this other thread helpful:

> [@Is there a simple way to find the variable with the highest value out of a group?](https://forum.choiceofgames.com/t/is-there-a-simple-way-to-find-the-variable-with-the-highest-value-out-of-a-group/28964):
>
> (Hello! My first post - diving right in with a question slight_smile) I’ve already found a way to do this, but I was wondering if there was an easier one! I wanted to have my game’s plot change based on which of several character stats was currently highest. So far, I’ve used a bunch of \*if commands to check each variable to see if it was higher than all the others, but it’s pretty messy with six different variables to compare: \*temp sympathy \*temp severity \*temp independence \*temp disciplin…

---

<div class="post-metadata">

**Author:** ![Gower](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/gower/32/21972_2.png) [@Gower](https://forum.choiceofgames.com/u/Gower)\
**Post date:** [November 25, 2017, 9:33pm UTC](https://forum.choiceofgames.com/t/min-max-command/32646/6 "2017-11-25T21:33:58Z")

</div>

Right, that’s a good point: in my solution, you have to pick which variable “wins” ties based on the order you place them in the list. If you want the check to return multiple answers if there is a tie for first place, for example, you need a bit more code.

---

<div class="post-metadata">

**Author:** ![TimberWoolf](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/timberwoolf/32/69602_2.png) [@TimberWoolf](https://forum.choiceofgames.com/u/TimberWoolf)\
**Post date:** [December 13, 2017, 3:52pm UTC](https://forum.choiceofgames.com/t/min-max-command/32646/7 "2017-12-13T15:52:47Z")

</div>

> [@GoldenSilver](#):
>
> selecting the highest or lowest opposed\_pair

I believe for this you’ll just need to use the stat that determines the opposed pair.

I work on a little bit of code, but this is mostly tailored to @Alexandra 's post about finding the simplest way to isolate the highest variable (also maybe useful for referring to multiple times throughout the story).

> **Code**
>
> ```choicescript
> *create strength 50
> *create dexterity 50
> *create intellect 50
> *create charisma 50
> *create tact 50
> *create subterfuge 50
> 
> *comment The stats we want to compare, after the game has run:
> 
> *rand strength 1 100
> *rand dexterity 1 100
> *rand intellect 1 100
> *rand charisma 1 100
> *rand tact 1 100
> *rand subterfuge 1 100
> 
> *comment Creating empty variables for as many stats as you wish, and then assigning them:
> 
> *temp var1 0
> *temp var2 0
> *temp var3 0
> *temp var4 0
> *temp var5 0
> *temp var6 0
> 
> *set var1 strength
> *set var2 dexterity
> *set var3 intellect
> *set var4 charisma
> *set var5 tact
> *set var6 subterfuge
> 
> *comment Four placeholder stats that will change based on the test:
> 
> *temp placeholder1 1
> *temp placeholder2 "var1"
> *temp placeholder3 2
> *temp placeholder4 "var2"
> 
> *temp winner "none"
> 
> *goto test
> 
> *comment For dynamically comparing the stats/ Also contains the breakpoint - We have six stats, so the test should stop once we've compared the sixth:
> 
> *label increase_first
> *set placeholder1 + 1
> *set placeholder2 "var" & placeholder1
> *if placeholder1 > 6
> *set winner placeholder4
> *goto print
> *else
> *goto test
> 
> *label increase_second
> *set placeholder3 + 1
> *set placeholder4 "var" & placeholder3
> *if placeholder3 > 6
> *set winner placeholder2
> *goto print
> *else
> *goto test
> 
> *comment The actual test- just four lines:
> 
> *label test
> *if {placeholder2} > {placeholder4}
> *goto increase_second
> *else
> *goto increase_first
> 
> *comment For this test, I decided to print the values first, for the user to see:
> 
> *label print
> 
> Strength: ${strength}
> 
> Dexterity: ${dexterity}
> 
> Intellect: ${intellect}
> 
> Charisma: ${charisma}
> 
> Tact: ${tact}
> 
> Subterfuge: ${subterfuge}
> 
> *comment This refers to the most favourable outcome - the highest stat. We've already correlated the variables here to a stat (var1 = Strength), so if we wanted a unique outcome for strength, we's ut that under the label 'var1':
> 
> It was predicted that you were mostly 
> *goto {winner}
> *label var1
> strong.
> *finish
> *label var2
> dexterous.
> *finish
> *label var3
> smart.
> *finish
> *label var4
> charismatic.
> *finish
> *label var5
> tactful.
> *finish
> *label var6
> sneaky.
> *finish
> 
> ```
> 
> Pop that into an empty startup file and play around. I’m not really sure how to weight ties, but considering that this allows for only _one_ unique outcome, I’m sure it’s okay for the first stat to take precedence. Unless somebody can figure out how to flavour that into this. That would be great.

It’s a little bit much, but it’s basically a general formula that might be useful. The only thing to do is link the variables to the stats in the specified section, and make sure the breakpoint is the number of the highest variable.

[Edit to add]  
In hindsight, I can’t imagine a game with enough variables to make _this_ code the economic and efficient choice. 🤣🤣🤣
