Return highest value of array?

Posted: 22 Mar 2022 18:52
by gradstein

Is there a way in naninovel to return the highest value of an array?

For example, if I have 6 characters, all with numerical scores represented by CHARACTER1SCORE etc, how do I check them all against eachother to output the highest variable (or define a new variable with that value?)

I know unity can use var max = Mathf.Max(myArray) but not sure how to write that in Naninovel


Re: Return highest value of array?

Posted: 22 Mar 2022 19:16
by gradstein

ok so the following successfully prints the number 2, but what I need to know is that characterscore2 is the highest and be able to output that. i can't just if check the two because i have 5 variables. The goal is to show you the character with the highest score, not print what the highest score was

@set characterscore1=1
@set characterscore2=2
@set TESTSCORE=Max(characterscore1,characterscore2)
@print {TESTSCORE}


Re: Return highest value of array?

Posted: 23 Mar 2022 08:13
by idaot

Mathf.Max can read more than two values. Tested it and had no issues.


Re: Return highest value of array?

Posted: 24 Mar 2022 20:03
by gradstein

you are right, i just hadn't predefined the varialbes and it didn't like that. so back to the original question, which was how to output the character with the highest score when i have 5 characters.


Re: Return highest value of array?

Posted: 25 Mar 2022 09:36
by idaot

I suggest making a custom expression which performs the necessary calculations in C# and returns a string corresponding the actor id with the highest score: https://naninovel.com/guide/script-expr ... -functions