Checking several switches efficiently

Stupidbro

Veteran
Veteran
Joined
Jul 8, 2019
Messages
87
Reaction score
8
First Language
English
Primarily Uses
RMVXA
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?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
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.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
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]}
 

Stupidbro

Veteran
Veteran
Joined
Jul 8, 2019
Messages
87
Reaction score
8
First Language
English
Primarily Uses
RMVXA
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)
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,425
Reaction score
7,710
First Language
German
Primarily Uses
RMMV
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)
 

Stupidbro

Veteran
Veteran
Joined
Jul 8, 2019
Messages
87
Reaction score
8
First Language
English
Primarily Uses
RMVXA
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,017
Messages
1,018,356
Members
137,802
Latest member
rencarbali
Top