Get Game Switches by Name Rather than Number

DemiDawnfall

Villager
Member
Joined
Nov 6, 2019
Messages
8
Reaction score
4
First Language
English
Primarily Uses
RMMV
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
 

Soulrender

Veteran
Veteran
Joined
Jan 12, 2019
Messages
363
Reaction score
219
First Language
Poland
Primarily Uses
RMMV
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.
 

DemiDawnfall

Villager
Member
Joined
Nov 6, 2019
Messages
8
Reaction score
4
First Language
English
Primarily Uses
RMMV
@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).
 

Soulrender

Veteran
Veteran
Joined
Jan 12, 2019
Messages
363
Reaction score
219
First Language
Poland
Primarily Uses
RMMV
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 :)
 

DemiDawnfall

Villager
Member
Joined
Nov 6, 2019
Messages
8
Reaction score
4
First Language
English
Primarily Uses
RMMV
Wonderful! If it's just in a JSON file then that's all I need! Thanks man. Thread can be closed. :)
 

Soulrender

Veteran
Veteran
Joined
Jan 12, 2019
Messages
363
Reaction score
219
First Language
Poland
Primarily Uses
RMMV
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.
 

DemiDawnfall

Villager
Member
Joined
Nov 6, 2019
Messages
8
Reaction score
4
First Language
English
Primarily Uses
RMMV
Heck yeah! Thanks for making my life so much easier. ^u^
 

Soulrender

Veteran
Veteran
Joined
Jan 12, 2019
Messages
363
Reaction score
219
First Language
Poland
Primarily Uses
RMMV
Not a problem, it might be useful for me as well :)
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
591
Reaction score
156
First Language
Javascript
Primarily Uses
RMMV
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
 
Last edited:

DemiDawnfall

Villager
Member
Joined
Nov 6, 2019
Messages
8
Reaction score
4
First Language
English
Primarily Uses
RMMV
Yup! That seems sound in theory! Thanks for the elegant alternative!
 

Soulrender

Veteran
Veteran
Joined
Jan 12, 2019
Messages
363
Reaction score
219
First Language
Poland
Primarily Uses
RMMV
@ct_bolt Wow, I didn't think about that approach. It's even better solution than mine :)
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Made Custom ENEMY Information Screen
I'm having such a hard time thinking of an interesting battle system. and not being a coder, certain things I wanna do seem a lot harder lol.
Created a character outline with some code. I have no use for this. I'm....bored.....
Having lots of fun using different PS brushes to add a lil' texture to the floors and walls in my maps.

Forum statistics

Threads
93,721
Messages
914,914
Members
123,324
Latest member
ahmbor
Top