Selecting Variables from a List

Is it possible to set up a list of existing Variables and have it select the one with the highest amount to determine a scene for a game?

Preferably without Plugins please.
Um...maybe? Can you be a bit more descriptive about what you're trying to do?

I'm not sure whether you're saying "scene" the way RPG Maker uses scenes, as a collection of windows - that would mean JavaScript code, which is the same as a plugin.

Or whether you mean "scene" like something that's happening in a cutscene in your game, in which case I can't think why you can't just use Conditional Branches in an event.
Yes and it would probably involve an array and the sort function.
Just set aside another variable for the result and keep a running tally. E.g. to get the maximum value from three variables:

◆Control Variables:#0030 Result = Slot 1 ◆If:Slot 2 > Result ◆Control Variables:#0030 Result = Slot 2 ◆ :End ◆If:Slot 3 > Result ◆Control Variables:#0030 Result = Slot 3 ◆ :End ◆Text:None, Window, Bottom : :Maximum value of \v[27], \v[28], and \v[29] is: : : : :\v[30]
Yes and it would probably involve an array and the sort function.
If you're going the JavaScript route, reduce would be a little fancier than sort:
JavaScript:
let result = [4, 5, 6, 7].reduce((a, b) => Math.max($gameVariables.value(a), $gameVariables.value(b)));
Um...maybe? Can you be a bit more descriptive about what you're trying to do?

I'm not sure whether you're saying "scene" the way RPG Maker uses scenes, as a collection of windows - that would mean JavaScript code, which is the same as a plugin.

Or whether you mean "scene" like something that's happening in a cutscene in your game, in which case I can't think why you can't just use Conditional Branches in an event.
Sure. I'll use an example.

Let's say you're playing a Dating Sim and every action you do gains one point to one character, then at a certain point, it'll check all the characters to see who has the highest points and will initiate a specific scene for that character.

I'm basically looking for the means to check all Variables from a list like this and automatically pick either the highest or lowest.
If you're going the JavaScript route, reduce would be a little fancier than sort:
JavaScript:
let result = [4, 5, 6, 7].reduce((a, b) => Math.max($gameVariables.value(a), $gameVariables.value(b)));
Why not use Math.max.apply and just pass the array in directly?
Why not use Math.max.apply and just pass the array in directly?
Well, if I were to feed an array to Math.max, I'd probably actually use the spread operator, rather than apply:
JavaScript:
let result = Math.max(...[4, 5, 6, 7].map(id => $gameVariables.value(id)));

That solution was actually my first thought, but then I decided that I liked the reduce method a little better.

Official reason: The reduce solution handles everything in one loop. On the other hand, the other solution actually iterates through the array twice (first to map it to the values of the game variables, and then again after it gets passed to Math.max).

While the performance difference with an array of this size would be infinitesimal, and performance isn't a concern in this situation anyway, it still feels a little more elegant (to me) when I can do things in a theoretically more performant way without sacrificing readability or needing to do any extra work or anything like that.

Real reason: I never get to use reduce, so when I saw an opportunity, I jumped at it.
Well, if I were to feed an array to Math.max, I'd probably actually use the spread operator, rather than apply:
JavaScript:
let result = Math.max(...[4, 5, 6, 7].map(id => $gameVariables.value(id)));

That solution was actually my first thought, but then I decided that I liked the reduce method a little better.

Official reason: The reduce solution handles everything in one loop. On the other hand, the other solution actually iterates through the array twice (first to map it to the values of the game variables, and then again after it gets passed to Math.max).

While the performance difference with an array of this size would be infinitesimal, and performance isn't a concern in this situation anyway, it still feels a little more elegant (to me) when I can do things in a theoretically more performant way without sacrificing readability or needing to do any extra work or anything like that.

Real reason: I never get to use reduce, so when I saw an opportunity, I jumped at it.
Leveraging excuses to use reduce is always valid. (also the reason I suggested .apply instead of the spread operator was that this was for MV and not all versions of it support that)

Original thread: https://forums.rpgmakerweb.com/threads/selecting-variables-from-a-list.158981/