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.
Preferably without Plugins please.
◆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]If you're going the JavaScript route,
reduce would be a little fancier than sort:let result = [4, 5, 6, 7].reduce((a, b) => Math.max($gameVariables.value(a), $gameVariables.value(b)));
Sure. I'll use an example.
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:let result = Math.max(...[4, 5, 6, 7].map(id => $gameVariables.value(id)));
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).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/