How to check if an event has switches?

Yurii

Villager
Member
Joined
Apr 10, 2016
Messages
21
Reaction score
2
Primarily Uses
UPD: SOLVED—see the solution below.


I'm writing a plugin to control self-switches remotely from other events. It's already working pretty well.


Although, I'd like to add a debug message whether an event, which self-switch I want to change to, does not have that specific self-switch.


In other words:


1) Plugin Command in Event1 says 'ChangeSelfSwitch Event002 A' (it's shorter actually),


2) Event2 does not have this A self-switch


3) An alert with 'Event002 does not have A switch' appears.


Could you please advise what should I write in IF statement for the above to happen?
Thank you!
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,002
First Language
Tagalog
Primarily Uses
RMVXA
AFAIK, the default self switches will always exist as long as that event exist, so I'm not sure if checking if it exists will return false... But basically if you want to check it, you just need to check if that self switch is null or not. If it's null then you can assume it doesn't exist. You can do that by just using the same code ur using to modify it, but instead of setting a value, make a comparison instead.


Can you explain why you want to check it first? I don't see any problem even if you end up changing a self switch that is not used or non existent anyway so why bother checking it?
 
Last edited by a moderator:

Yurii

Villager
Member
Joined
Apr 10, 2016
Messages
21
Reaction score
2
Primarily Uses
AFAIK, the default self switches will always exist as long as that event exist, so I'm not sure if checking if it exists will return false... But basically if you want to check it, you just need to check if that self switch is null or not. If it's null then you can assume it doesn't exist. You can do that by just using the same code ur using to modify it, but instead of setting a value, make a comparison instead.


Can you explain why you want to check it first? I don't see any problem even if you end up changing a self switch that is not used or non existent anyway so why bother checking it?
Thank you for answering.


Actually, I need this check only to find out (using my example) if I forgot to create 'A' switch in Event2; just for convenience.


This would be very helpful for multiple event switching, i.e., when I make a string without spaces as an argument#1 (something like “1,2,3,45,12,66,77” ), but already missed to make an event page with 'A' switch in one of those events.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,042
Reaction score
13,678
First Language
English
Primarily Uses
RMMV
I haven't tested these, but here are some possibilities I came up with via a quick Google search:

Code:
if (!([mapid, eventid, 'selfswitchid'] in $gameSelfSwitches._data) {
  // the self switch does not exist
}



if (!$gameSelfSwitches._data.hasOwnProperty([mapid, eventid, 'selfswitchid'])) {
  // the self switch does not exist
}
These will both check if the self switch does not exist at all.


Note that when you set a self switch to false, it does NOT set the key to false in $gameSelfSwitches - it deletes it.  So if you set a self switch to false, the above will tell you the self switch does not exist.  Also, if you check the value of a self switch via $gameSelfSwitches.value([mapid, eventid, 'selfswitchid']) and it doesn't exist, it will return false.


Are you aware there's already a plugin that allows you to change one event's self switch from within another event?  It's one of the Kadokawa plugins that ships with the engine.
 

Yurii

Villager
Member
Joined
Apr 10, 2016
Messages
21
Reaction score
2
Primarily Uses
Unfortunately, both suggestions check only if a switch is already enabled, similarly to


$gameSelfSwitches.value([mapid, eventid, 'selfswitchid'])


Probably, the solution comes with checking if an event page exists, and if switching to the page meets conditions...


However, I just can't figure out how to use this part of the code about event pages from rpg_objects.js yet.
 
Last edited by a moderator:

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
You could check the events pages to see if a self-switch is valid, in other words, if the user had marked the self-switch option to on, then it will return true. I've recently had to do this for my farm plugin, I had to ensure that the next pages self-switch option were true before allowing my plugin to automatically turn it on. Not 100% sure if this is what you are talking about or not.


This image shows the events array inside $dataMap, you can see that all events have a pages array and inside that a conditions object, the conditions object is where you can see if a selfSwitch or any of the switch/variable options are set to true. So basically, once you tap into your event, you can do a for loop through all pages and then do a for in loop to check each property inside the conditions object, then you can evaluate your switches.


 Screenshot_2.png


I did a quick prototype of how this can be achieved, you can figure out how to retrieve the eventId on your own, I'm not sure if you want to check all events at once and store them for later or you just want to do it in real time, either way it's fairly simple to get the event id for this method below. Again, I'm not 100% sure if this was what you were looking for but I have a feeling it's close. Let me know and I'll see what else I could do for you.

Code:
	Class_Name.prototype.methodName = function (eventId) {
		var event = $dataMap.events[eventId];
		var pages = event.pages;


		var allPages = pages.length;
		for (var i = 0; i < allPages; i++) {
			var pc = pages[i].conditions;

			for (var condition in pc) {
				if (pc.hasOwnProperty(condition)) {
					console.log('Page Conditon: ', condition);
					console.log('Condition Value: ', pc[condition]);
					// Do your stuff here
				}
			}
		}
	};
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,042
Reaction score
13,678
First Language
English
Primarily Uses
RMMV
What are you trying to do?


I've already said that if you turn a self switch off, it will delete it, so if you use that command it could indicate the self switch has never been set OR that it was on and it's been turned off.


From that, you can tell there's no way to know if it ever existed.  If you try and reference a self switch and it doesn't exist, it will come back false.  


What are you trying to accomplish, that the existing Outer Self Switch does not already do?
 

Yurii

Villager
Member
Joined
Apr 10, 2016
Messages
21
Reaction score
2
Primarily Uses
What are you trying to accomplish, that the existing Outer Self Switch does not already do?
1) As I have checked, It does not allow to turn on a self switch in multiple events via one Plugin Command by default—that is NOT a problem, I've already made this function in my plugin.


2) What is more important, it won't show [because it was not coded to handle multiple events in one Plugin Command by default] that I have an error in a string of multiple events. Well, it does not show any errors at all ;)


Currently, I've already accomplished to show two errors: whether an event was deleted, or it never existed.


Now, I want a debug tool for my convenience to check whether I forgot to add a page with the self switch in a specific event.
Actually, the LTN Games's idea is quite interesting, I will get back to it as soon as I have some time.


SOLVED The check should be performed by page, as LTN Games advised. However it does not need another cycle, but only 2 If-checks: one if the switch exists on event pages, and the other to show an error message if the switch does not exist:

Code:
checkSSW = function (_mapid, _evid, _args1) {//_args1 is the element in Plugin comman array; in my case it is “args[1]”.
	var event = $dataMap.events[_evid];
	var pages = event.pages;
	var allPages = pages.length;
	var stoptrig = 1;
	for (var j = 0; j < allPages; j++) {
		var pcSSW = pages[j].conditions.selfSwitchCh;
		var pcSSWV = pages[j].conditions.selfSwitchValid; // These two variables are the properties of self switches on an event page.
		if(pcSSW===_args1 && pcSSWV) {
			stoptrig--;
			$gameSelfSwitches.setValue([_mapid, _evid, _args1], true);
		};
	};
	if (stoptrig===1){
		alert('ev no. ' + _evid + ' does not have SSW ' + _args1);
	};
};
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Happy Thanksgiving everyone! What are you thankful for? I'm thankful that I no longer have PTSD, and that I get to enjoy a good meal with my mom and stepdad! It might not be the same as before COVID, but at least I still get to enjoy the holiday!


Made another map, this one even has a cool moving waterfall. I'll have an animated GIF later whenever I'm done adding stuff. :LZSwink:
Back here again?! RPG MAKER, I can't quit you. :kaosigh:
um... why didn't anyone tell how easy it is to add motions to Sideview battlers? I literally copied the last one, changed the name and index, said where it should play, and boom... I've got intro motions.
Lately when I listen to 1970s songs, I always think that the "real world" is still at mid 70s. What we experience now is a futuristic dream. With this point of view, even 80s and 90s looks super futuristic. :D

Forum statistics

Threads
105,541
Messages
1,014,486
Members
137,220
Latest member
broiderers
Top