MV GalvPlugin Puzzle- Need help with checking Switches

Hello again!

I hope it's a small question for you.
I wanna use Galvs Puzzle Functions Plugin and its great, but I think I would need one more ScriptCall to use it as I want.

I want to make a little quiz to the beginning of my game, like in pokemon mystery dungeon I want it, that the Player can become a monster depending on how the player answers the questions of the quiz.

Because I would like to make a lot of questions and I would have possible 40-80 monsters to become, its hard just to use the scriptcall of the Script that ask: "Are all of these Switches on?" - then you get Monster A etc

I would like to have a scriptcall or something like this that would be like:
Which monster has the most switches on? and then randomize between monsters with the most switches.

Iam bad at explaining... maybe an example:
Player makes the test, Switch 1, 4, 6, 9, 12 are on after that
Monster 1 Needs Switches: 1, 4, 5, 8, 12 (= 3 matching switches)
Monster 2 Needs Switches: 2, 4, 6, 9, 11 (= 3 matching switches)
Monster 3 Needs Switches: 3, 7, 8, 9, 11 (= 1 matching Switch)
--> now I would need a Scriptcall that checks: Monster 1 and Monster 2 both have at least 3 matching Switches, these are the most matching switches of all possible monsters
--> Radomize between Monster 1 or Monster 2 (or more, if there are more monsters with the most matching switches)
--> depending on wich monster is randomized (maybe number of monster 1-80 saved in a variable) i can use a conditional branch to go on (change player to the monster)

Glavs Script is super great, but it needs that ALL needed Switches are on, and not "at least 2/3 Switches are on"

Its not as short as I hoped, but maybe the solution is more short?
thank you, if you have read till now!
I'm going to ignore the reference to the Galv plugin because from your description it doesn't seem relevant.

If I'm wrong, and you're actually using that plugin for some part of this process, we can refine from there. But I'm going off of you have an event with a series of choices, each one of which turns a switch on or off.

Control Variables -> Monster1 -> Script -> [1, 4, 5, 8, 12].filter(element => $gameSwitches.value(element)).length
Control Variables -> Monster2 -> Script -> [2,4, 6, 9, 11].filter(element => $gameSwitches.value(element)).length
etc.
That line of code will assign the number of ON switches to each variable.

For the sake of example, I'm pretending the variables you're storing that into are 1-40 for the 40 monsters.

Then you would do
Control Variables -> Monster1 -> Script -> [...Array(40).keys()].map(x => ++x).reduce((a, b) => Math.max($gameVariables.value(a), $gameVariables.value(b)), -Infinity)
Now Monster1 is storing the ID of the variable that had the most ON switches.
Scripts are not miracle workers, and computers are not really artificial intelligences - no matter how often that is claimed as a buzzwort.

What you want cannot be done in a single script call, it needs a full script function.
You can write that function into a plugin and then use a call to that function to make things simpler, but the step between requires a lot of commands and comparisons.

Unfortunately your example does not provide enough details to even start programming such a function

EDIT: I stand corrected - you can start, but it should be obvious from the post above that there is more to it...
Why even use switches for this? Seems like it would be smarter to have each answer to a question add to a specific variable, then check to see which variable is highest at the end and give the player their character based on that.
@Sword_of_Dusk That occurred to me, too, after my post 🙂

You could put after each answer a Control Variables that adds 1 to each monster type it contributes to, instead of a Control Switch that turns on a switch that potentially affects multiple monster types.

It would eliminate the need for those first few script calls, but might make the overall event longer.

A valid, simpler approach.

Then you'd use the last bit to determine which of the variables had the highest value.

Original thread: https://forums.rpgmakerweb.com/threads/galvplugin-puzzle-need-help-with-checking-switches.162707/