Return highest value of array?

Discuss authoring naninovel scenario scripts.
Post Reply
gradstein
Posts: 22
Joined: 09 Sep 2020 19:03

Return highest value of array?

Post 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

gradstein
Posts: 22
Joined: 09 Sep 2020 19:03

Re: Return highest value of array?

Post 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}

idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: Return highest value of array?

Post by idaot »

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

gradstein
Posts: 22
Joined: 09 Sep 2020 19:03

Re: Return highest value of array?

Post 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.

idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: Return highest value of array?

Post 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

Post Reply