Currently, I'm working on a project where the main character gathers faith in nine virtues. At the end of the game, the character will be judged on which virtue they succeed in(which one has the highest variable). However, I need a way for the game to pick the virtue with the highest variable. Is there a way to do this?
Picking the highest variable
RPG Maker MV SupportThis is possible without scripting, e.g.
Alternatively, you could try Control Variables -> Script:
This should store the ID of the variable with highest value, from variable IDs 51~59 inclusive. You'll probably need to edit the numbers to fit your variable IDs: note that 51, the first ID, is at the end of the script call rather than the start.
In the event of a tie, both of these approaches prioritise earlier values. E.g. if virtue 2 and virtue 3 are both 5, and all the rest are 0, virtue 2 will be identified as having the highest value.
◆Control Variables:#0050 Index = 1
◆Control Variables:#0051 Value = Value 1
◆If:Value < Value 2
◆Control Variables:#0050 Index = 2
◆Control Variables:#0051 Value = Value 2
◆
:End
◆If:Value < Value 3
◆Control Variables:#0050 Index = 3
◆Control Variables:#0051 Value = Value 3
◆
:End
◆Comment:etc...
◆Text:None, Window, Bottom
: :TEST: virtue \v[50] is highest, with a value of \v[51].Alternatively, you could try Control Variables -> Script:
[52,53,54,55,56,57,58,59].reduce(function(a, c) { return $gameVariables.value(c) > $gameVariables.value(a) ? c : a; }, 51);This should store the ID of the variable with highest value, from variable IDs 51~59 inclusive. You'll probably need to edit the numbers to fit your variable IDs: note that 51, the first ID, is at the end of the script call rather than the start.
In the event of a tie, both of these approaches prioritise earlier values. E.g. if virtue 2 and virtue 3 are both 5, and all the rest are 0, virtue 2 will be identified as having the highest value.
I think I will do the non-scripting, but I need more details about it. For example, is the index where all other variables are compared? I just need a breakdown in case I miss a step.
Just look at the whole thing she posted. The only purpose of "Index" (or variable 50 in the example) is to store the number of the highest-value Virtue, used in the bottom Show Text.
If you don't care about having a reference point to which Virtue it is, and you only care about the actual value, then that doesn't matter to you.
Yep, like Turan said! Basically, they line up like this:
"Index" is different for each virtue, so it can be used to track where "Value" came from. 👋
[Edit: added "Variable ID" row to the table above, to help clarify things.]
Variable ID: 51 52 53 54 55 etc (<- these are the IDs in my example)
Index: 1 2 3 4 5 etc
Value: 4 6 1 0 1 etc (<- these are just example values)"Index" is different for each virtue, so it can be used to track where "Value" came from. 👋
[Edit: added "Variable ID" row to the table above, to help clarify things.]
One last thing, Value and Value 1 are different variables and not meant to be the same variables?
Yes. The event I posted was a direct "Copy as Text" from the editor window.
The variables named "Value 1" etc are inputs: their values have already been set elsewhere.
- "Value 1" is the variable where the value of the first virtue is already stored.
- "Value 2" is the variable where the value of the second virtue is already stored.
- Etc.
- "Value" is the variable where the highest value for all virtues gets stored.
- "Index" is the variable where the "ID" of the highest-value virtue gets stored.
Original thread: https://forums.rpgmakerweb.com/threads/picking-the-highest-variable.172739/