Is there a way to get a list of all switches on all maps regardless of names?

We can start with an example (you never give us an example output).
Say, if switch 1 is used in 3 events, twice in event 1, three times in event 2, and once in event 3, what to output?

Switch 1: 3
OR
Switch 1: 6
I tried to make an assumption about what it is you want, need, and expect. Unfortunately, this thread is too confusing for me to even know where to start.


Your title is conflicting: "on all maps" suggests that you're asking about Self Switches (only Self Switches are tied to maps), but "regardless of names" suggests you're asking about regular Switches (Self Switches don't have names).

I even considered the possibility that you might be talking about the Event Searcher, but I'm currently looking at Map 006, searching for Switch 0001, and I'm getting a hit for Map 005. Since you mentioned "on all maps" and that's precisely how the Event Searcher works, you're probably talking about something completely different. Also, the Event Searcher uses names only for Events, not Switches.


I honestly have no clue what you're asking about, sorry.
We can start with an example (you never give us an example output).
Say, if switch 1 is used in 3 events, twice in event 1, three times in event 2, and once in event 3, what to output?

Switch 1: 3
OR
Switch 1: 6
The latter, ideally. I'd like to know, basically, how complex a game is from its usage of switches... as even a lot of maps can simply be empty, I think that is a more sensible way to estimate.

And Nolonar, I suppose self-switches are even tied just to events, rather than maps... but, really, it would be useful if the software had a mechanism to count all the tick boxes under 'conditions'... right now I don't suppose there's even an automated way to count all events, though.
To get the list of all switches, global switches, use following script:
Code:
$dataSystem.switches.forEach(function(s){
console.log(s);
})

Obtaining SelfSwitches will be more difficult, because selfSwitches are used within events on maps so with second part I wonn't help, because my idea to get list of all selfSwitches backfired.
JavaScript:
var Theo = Theo || {}
Theo.Tracker = {
    Switches: function(){
        allMaps = {}
        resultSwitches = {}
        dtmLoadDataFile = DataManager.loadDataFile
        dtmOnXhrLoad = DataManager.onXhrLoad
        DataManager.loadDataFile = function(name, src){
            const xhr = new XMLHttpRequest();
            const url = "data/" + src;
            allMaps[name] = null;
            xhr.open("GET", url);
            xhr.overrideMimeType("application/json");
            xhr.onload = () => this.onXhrLoad(xhr, name, src, url);
            xhr.onerror = () => this.onXhrError(name, src, url);
            xhr.send();
        }
        DataManager.onXhrLoad = function(xhr, name, src, url) {
            if (xhr.status < 400) {
                allMaps[name] = JSON.parse(xhr.responseText);
                this.onLoad(allMaps[name]);
            } else {
                this.onXhrError(name, src, url);
            }
        };
        const recordSwitch = (switchId) => {
            resultSwitches[switchId] ||= 0
            resultSwitches[switchId] += 1
        }
        const allMapNames = $dataMapInfos.filter(m => m !== null).map(m => m.id)
        const intervalfunc = () => {
            allLoaded = allMapNames.every(m => allMaps[m] !== null)
            if (allLoaded){               
                for(const mapId of Object.keys(allMaps)){
                    map = allMaps[mapId]
                    map.id = mapId
                    //console.log(map)
                    events = map.events.filter(e => e !== null)
                    for(const ev of events){
                        for(const page of ev.pages){
                            if(page.conditions.switch1Valid){
                                recordSwitch(page.conditions.switch1Id)
                            }
                            if(page.conditions.switch2Valid){
                                recordSwitch(page.conditions.switch2Id)
                            }
                            for(const cmd of page.list){
                                if(cmd.code === 121){
                                    for (let i = cmd.parameters[0]; i <= cmd.parameters[1]; i++) {
                                        recordSwitch(i)
                                    }
                                }
                                if (cmd.code === 111 && cmd.parameters[0] === 0){
                                    recordSwitch(cmd.parameters[1])
                                }
                            }
                        }
                    }
                }
                DataManager.loadDataFile = dtmLoadDataFile
                DataManager.onXhrLoad = DataManager.onXhrLoad
                clearInterval(intervalChecker)
                console.log(resultSwitches)
            }
        }
        for(const map of $dataMapInfos){
            if (map !== null)
            DataManager.loadDataFile(map.id, "Map%1.json".format(map.id.padZero(3)))
        }
        const intervalChecker = setInterval(intervalfunc, 5)
    }
}
Save this as a plugin.

Usage:
Use console command Theo.Tracker.Switches()
Output:
Screenshot_944.jpg

Switch 1 is used 3 times, switch 2 is used once.

I'm not doing more than this.

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-way-to-get-a-list-of-all-switches-on-all-maps-regardless-of-names.142895/