Checking several switches efficiently

So, fundamentally, what I'm trying to do is check a lot of switches at once and produce a quantity for how many in that range are on. As Ace doesn't have this built in, I tried making this loop:
IMG_20200520_164413034.jpg

However, when this common event is run, it won't ever return a value larger than 3, even though there are 37 switches it's supposed to check. Through some debugging, I've figured out that the three that it IS registering are 2, 8, and 27. Am I doing something wrong? Ideas and suggestions?
Please use Alt + PrintScreen to get screenshots. Photos from mobile phones are so hard to look at, with the weird angle, the glare and the poor focus.

Your script call is wrong. Switches are not "ON" or "OFF" in script - they are true and false. And because $game_switches[id] == true returns true when it's on and false when it's off, you don't even need to include the == true.

It would also help if you give your switches decent names. Switch 3 is called #2, and you're also using switch 2 which is called #, so it's very confusing to follow.

Are you SURE there are more than those 3 switches turned on?

There are other easier ways to do it via scripting, but I don't have time to work out the syntax and check. I'm sure someone else will though.
I'm sure someone else will though.
I'll bite. Here is the syntax.
Code:
37.times {|i| $game_variables[2] += 1 if $game_switches[i+1]}
It would also help if you give your switches decent names. Switch 3 is called #2, and you're also using switch 2 which is called #, so it's very confusing to follow.
Sorry about that. It's not too confusing to me, but I do see how that could be potentially confusing to others. I just use those whenever I need an rng value, so they're used all over the place and I couldn't come up with a good variable name for them.
Are you SURE there are more than those 3 switches turned on?
Yes. I literally set every switch in that range to ON and still got three.
I'll bite. Here is the syntax.
Code:
37.times {|i| $game_variables[2] += 1 if $game_switches[i+1]}
Thanks to the both of you; I'll try both solutions and let you know the results!

Edit: So, changing the conditional worked, transcribing the script did not (it crashed the game)
I couldn't come up with a good variable name for them.
The usual name for such variables is TEMP or TEMP1 to TEMP9 (depending on how many you reserve)
The usual name for such variables is TEMP or TEMP1 to TEMP9 (depending on how many you reserve)
I'll keep that in mind for future games.

Original thread: https://forums.rpgmakerweb.com/threads/checking-several-switches-efficiently.121827/