• News

• Industries

• Learning & Support

• Community

• Marketplace

# Comparing multple values in different combinations

Hey Guys

Looking for a little help. Trying to find a way to do this comparison.
Basically, I have 3 stats, eg, Hunger/Thirst/Oxygen. Now, at times, I can do something that can alter none, one or all of the stats at once.

What I would like to do, is after I do that thing, I would like to get the values of all the 3 stats only if they were altered and then from those, compare which one was altered the most (eg: which value is now the highest). and return that stat type and value.

Now, I can determine which stat was changed when an action takes place and it’s new value, but what i’m not sure on is how I then go about comparing only those that were changed with each other. Sometimes no stat changes and so I don’t need to compare anything, sometimes 2 of the 3 stats change so I need to compare just those, sometimes all 3 change and so I need to compare all 3 etc.

I could probably get this done using many branches (one for every possible combination), but I was wondering if there was an easier way i’m missing. In my head, this seems like this should be easy, but i’m currently drawing a blank on how to accomplish it.

So sometimes I compare nothing, sometimes i compare all 3, sometimes only hunger and thirst, or hunger and oxygen, or oxygen and thirst. I currently have a bool that gets set to true if the stat changes, but how do I go about comparing only those that change?

I hope i’ve explained this well enough. Any help would be appreciated.

I don’t think there’s a neat way of doing this.

I tried it with structures, arrays of structures, and maps. Big mess.

Probably the easiest way is 3 arrays. One is current stats, next is previous stats and the third is differences.

Even then, to update all 3 looks like:

Yuk.

Might be easier with a function to update one stat, that returns the difference:

Nope…

But at least it’s neat when you call it:

If you only need to check which stats were changed, why not only add them to a list (stat index, stat value) to be compared when you directly change them? Then you can run a function that loops through this list and does comparisons, returning both the index of the stat that fits your criteria and the amount it was changed by, then clear the list. That would eliminate any need for comparing current stats to old stats since the only entries in your list will be values you already know are changed.

Thanks guys for both your responses. I’ll look into both suggestions and see how I go. If I can use arrays and loops to do this rather than the 100 branches i was using before then that’s the way to go. Thanks again.