Sometimes I have found that it seems onerous or wasteful to create map/global switches for one-off events. Sometimes I wish I could have a cutscene event tell another event that it needs to change its state and keep those state changes local/encapsulated to each event.
I've added a plugin command called SELFSWITCH which will allow one event to control the "self switch" of another event.
SELFSWITCH <event_id> [switch=A|B|C|D] [value=ON|OFF]E.g.:
SELFSWITCH 1 A ONThere may be a better way to accomplish this but I hope maybe this little script will come in handy for someone else.
https://github.com/caseylutz/KCL-MV/blob/master/KCL_SetSelfSwitch.js
If you use a helper library, FindEventByName, then you can call out your event ID by its canonical name rather than its event ID number.
https://github.com/caseylutz/KCL-MV/blob/master/KCL_FindEventByName.js
E.g.:
SELFSWITCH ENGLISH_VILLAGER_001 B ONNote: You may omit the switch and value parameters. The defaults will be "A" and "ON" respectively.
EDIT: Plug-in moved to GitHub.
Set another event's selfswitch
● ARCHIVED · READ-ONLY
-
-
In FindEventByName, I would suggest you replace this,
return this.events().filter(function(e) {
return e.event().name == name;
})[0];
With this,
return this.events().find(function(e) {
return e.event().name == name;
});
Your code will unnecessarily search the entire array of events even once it finds the one you're looking for, and allocate an array containing it, only to throw it away immediately. -
Great suggestion, thanks! Totally agree. Unfortunately, I can't use Array.prototype.find() as it's ES6-only and RPGMaker's JS engine (at least here on OSX) doesn't have it yet. I could polyfill it but I'd prefer that to go into a core library if necessary.In FindEventByName, I would suggest you replace this,
return this.events().filter(function(e) {
return e.event().name == name;
})[0];
With this,
return this.events().find(function(e) {
return e.event().name == name;
});
Your code will unnecessarily search the entire array of events even once it finds the one you're looking for, and allocate an array containing it, only to throw it away immediately.
In the long run I'm going to end up wrapping Lo-Dash into a utility library for just this very reason but I don't have enough going on at this point to justify it just yet.
I have, though, updated the FindEventByName plugin to eliminate overriding a default Game_Map call in favor of just adding a function to it. I've also moved the plugin over to GitHub. I will update the pastebin link(s) above as necessary.
https://github.com/caseylutz/KCL-MV/blob/master/KCL_FindEventByName.js -
There is a plug in by Kadokawa in the bonus pack called Outer Self Switch which does this. You might want to study how they did it and compare it to your own code.
-
Good find! Didn't even notice that in there. Definitely would have saved me a little time there. The method looks nearly identical, the only real value I see this plugin providing, then, in this case is identifying events by "name" rather than numerical ID.There is a plug in by Kadokawa in the bonus pack called Outer Self Switch which does this. You might want to study how they did it and compare it to your own code.
Thanks! -
Oops. :) I've been poly-filling Array.prototype.find and related functions for so long that I forgot some of them aren't natively implemented yet.Great suggestion, thanks! Totally agree. Unfortunately, I can't use Array.prototype.find() as it's ES6-only and RPGMaker's JS engine (at least here on OSX) doesn't have it yet. I could polyfill it but I'd prefer that to go into a core library if necessary.
In the long run I'm going to end up wrapping Lo-Dash into a utility library for just this very reason but I don't have enough going on at this point to justify it just yet.
I have, though, updated the FindEventByName plugin to eliminate overriding a default Game_Map call in favor of just adding a function to it. I've also moved the plugin over to GitHub. I will update the pastebin link(s) above as necessary.
https://github.com/caseylutz/KCL-MV/blob/master/KCL_FindEventByName.js
Awesome to see someone putting their plugins on GitHub. I hope this is a trend that continues. -
There's also a script call to do this very thing as well...
$gameSelfSwitches.setValue(key, true/false);
key = [mapId, eventId, A-D]
I've never actually used it, but I intend to try it eventually... -
Hey, I'm not sure what I'm doing wrong here, but I have a plugin command run at the end of an event that says "SELFSWITCH potion A ON" and my "potion" event doesn't switch. I even tried it with an event ID with no luck. Any help would be much appreciated.
-
Is the case and spelling the same? Do you have a second page on that event conditioned by self switch A? Might help to post some screenshots if that doesn't get you anywhere.
-
I use the script call:
var key = [map id, event id, selfswitch];
$gameSelfSwitches.setValue(key, true);
Ex:
Map Id: 001
Event id: 005
Self Switch: A
var key = [1, 5, 'A'];
$gameSelfSwitches.setValue(key, true);
It works smooth out of the box!
Tks anyway. Every added plugin is helpful for use or learning purpose. -
-
What's on page 3 of that event? If it has no conditions, or its conditions are met, THAT page will be active, and not page 2.
-
@Yui
Aside from not being able to see Tab #3 (which obviously could theoretically take precedence depending on what's set up there), nothing really stands out at me! That's pretty much identical to how I'm using the script as far as I can tell, except that in this case my tendency would be to omit the "A ON" part. -
http://imgur.com/a/rOVGi
Even after talking to the old lady I get the message "You cannot steal the healing potion". So it's not going to page 3. Maybe I have the plugin setup incorrectly?
http://imgur.com/3PBmklc
Sorry about two links I didn't think about posting a picture of the plugins until a little later. -
are they on the same map?
-
Almost right next to each other.
-
I'm setting up an identical test case. Unfortunately I'm not seeing the same behavior.
http://imgur.com/a/2iejk
I'm somewhat new to RPG Maker myself so I see the switch setting state "A" and not "B" but I also don't see the text from my event.
EDIT:
GOSH I'M DENSE. You need to set the State "A" part to Autorun instead of Action.
http://imgur.com/DpJbUjh -
No, why would you do that? If you wanted to give it automatically, just do it in the old lady event instead of changing the self switch at all.
Of course you could just set a switch when you talk to her, and have ONE page on the potion event that checks the switch - if it's on, give the potion, if it's off, say you can't have it. -
Setting it to autorun didn't work what the helllll. Also if I have to have it autorun does that mean that I won't be able to actually take the potion from the table? I feel like that'd just make it immediately run the event after I'm done talking to the lady.
EDIT: Not trying to add it automatically. Am I just using the wrong plugin in the first place for what I want to do? -
Yes, you don't want to set it to autorun. If you are happy to try a different approach without the plugin, just post the question in the MV Support forum and we'll continue the discussion there.