Get Game Switches by Name Rather than Number

Hello!

I'm reading Kinoar's documentation and looking for something I thought would be readily accessible, but for the life of me, I just can't find. Is there any way to get switches by the names assigned to them?

So far I can only find this method. Workable--as I can grab things by number--but not ideal:

$gameSwitches.setValue(switchId: number, value: boolean)

For a concrete example, could I retrieve the name 'Test Event' from event 1 here in any way?

RPGMV_2020-01-16_06-30-22.png
Natively it's not possible. Switches are boolean type so they can be in true or false state, editor is just to help you organize them, however there is a workaround I just came up

Code:
getSwitchName = function(switchId){
    var mySwitches = [
        "switch 1",
        "switch 2",
        "switch 3",
        "switch 4"
    ];
    return mySwitches(switchId);
}

with this you can store switches names like in editor, but I guess this is not exacly what you want.

But there could be a even better option, maybe they can be readed directly from data/system.json file, but I've never parsed json file with JS function so my help ends here.
@Soulrender I'd considered it, but I was hoping to avoid the issue of potentially creating names that don't match up and, as such, might accidentally map to the wrong Switch or Variable.

Is it possible to just pull the list of names stored side-by-side next to the switches? If they're also stored in an array, they should have corresponding IDs that creates an implicit link between them and the switches they represent and that'd also be workable (cutting out human error and all that).
I've just checked through my entire system.json file and switches names are stored there so you can pull names from there, but I didn't finish yet JS function to do that.

Remember, that what I'm trying to write will just pull names of switches and you won't be able to do
Code:
$gameSwitches.setValue('mySwitch', true/false);

I'm learning JS for a brief time ;]

Maybe more skilled JS coders will help you. I already tipped them where and how they can look 🙂
Wonderful! If it's just in a JSON file then that's all I need! Thanks man. Thread can be closed. 🙂
Wait!! I've got it!!

Code:
obtainSwitches = function(position){
    
    var obj = require('./data/system.json');
    JSON.stringify(obj);
    return obj.switches[position];

}

Save it as js file in plugins folder and call with script event
obtainSwitches(position)

type any number instead position and you will get switch name.
Heck yeah! Thanks for making my life so much easier. ^u^
Not a problem, it might be useful for me as well 🙂
Is there any way to get switches by the names assigned to them?

That would simply be:
Code:
$dataSystem['switches'][n]
Replace "n" with the position of the switch name you want.

To get the value using a name would be:
Code:
$gameSwitches.value($dataSystem['switches'].indexOf('Switch Name Goes Here'));
$gameSwitches.setValue($dataSystem['switches'].indexOf('Switch Name Goes Here'), true);
See my post here on how to do it with variables: click here to view
Yup! That seems sound in theory! Thanks for the elegant alternative!
Yup! That seems sound in theory! Thanks for the elegant alternative!
No prob happy to help. 🙂
@ct_bolt Wow, I didn't think about that approach. It's even better solution than mine 🙂

Original thread: https://forums.rpgmakerweb.com/threads/get-game-switches-by-name-rather-than-number.117321/