(Solved) Checking if Common Event Exists?

Hi all - again!

Simple question (hopefully) this time. Is there a script call to check if a common event by a certain ID exists?

I can only seem to find specific script calls to reserve, clear, or otherwise use commands from a common event - but not to directly reference it by its ID to check if it exists.

The reason I'd like to know is because I'm working on my first plugin, wherein one function is that common events may be called via variables that the user sets up in the parameters. It would be no problem if there was only the option to directly choose a common event (since I can set up the relevant plugin parameter to allow choosing directly from the database common events list) - but if the ID is specified by a variable, and that variable ends up with a value of which no common event ID exists, it's a problem as the game crashes if it attempts to run an undefined/nonexistent common event.

If there's no such script call to check this, it's not a huge deal as I could just leave the responsibility on the user to make sure they're setting their variables to correct/valid values... although it would be ideal to be able to provide a console.log error informing them what went wrong.

Thanks in advance 🙂
I think you can get error only if that Id is grather than amount of common events declared in database, otherwise even if there is an empty common event, it'll run with just nothing. So I think that you could use "amount of common events in database", but sadly I have no idea how to get this from database.
I could just leave the responsibility on the user to make sure they're setting their variables to correct/valid values
That is how almost every plugin writer handles it, and why we always suggest to configure a plugin before using it.
Best counterexamples are where the plugin uses game variables to transfer data from eventing, and the people who suddenly wonder why their events no longer work after they forgot to configure the variables to some unused ones.

you can use a trick to force people to configure your plugin however:
have one plugin property to default to trigger a warning message "please configure the plugin".
if a user adds the plugin without configuring it they get the message, but if they read the help and check the parameter there would be one "display warning yes/no" that needs to be changed to no for the warning to disappear.

const v = $gameVariables.value(123); 0 < v && v < $dataCommonEvents.length
Replace 123 with the ID of the game variable you want to check.

Note they're both < signs:
  • The 0th index (first entry) of any database array is null (IDs start at 1);
  • length counts index 0, so the last index is 1 less than length.
I think you can get error only if that Id is grather than amount of common events declared in database, otherwise even if there is an empty common event, it'll run with just nothing. So I think that you could use "amount of common events in database", but sadly I have no idea how to get this from database.
Perfect idea!! It looks like @caethyril knows how 🙂

Thank you so much caethyril!!

And, @Andar that's also not a bad idea! Since I have a way to check it now, I will probably go ahead and just make it log an error (instead of trying to run the event and crashing) - but in the future if I can't figure something out, I might take your advice here and ease up on the hand-holding lol 🙂
You're welcome, happy scripting!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-checking-if-common-event-exists.146541/