Min-Max command

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.

4 Likes

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
8 Likes

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

1 Like

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.

2 Likes

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:

1 Like

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.

1 Like

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
*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. :rofl::rofl::rofl: