MV How to get the total number of events for a map?

How to get the total number of events for a map?
For example I want to get the length of map 3.
In the editor? Just make a new event it will automatically number itself "event #X" where X is the total number of events in that map, counting the new dummy event you're making.


For processing it as a number in an event or any other need while the game is running:
You can set a control variable to a script and then add:

$gameMap.events().length

if im not mistaken this should numerically add the number of events on the current map you're in, remember to reset this variable before re-counting on another map.

corrected to proper syntax
Hi there!

Inside the game you can check the number of map events with the script call:

$gameMap.events().length

$game_map.events.size
@BK-tdm I believe that is a VX Ace syntax? On MV and MZ it's a little bit different ^^
For MV it would be $gameMap.events().length.

Edit: ninja'd.
For MV it would be $gameMap.events().length.

Edit: ninja'd.
Hi there!

Inside the game you can check the number of map events with the script call:

$gameMap.events().length


@BK-tdm I believe that is a VX Ace syntax? On MV and MZ it's a little bit different ^^
In the editor? Just make a new event it will automatically number itself "event #X" where X is the total number of events in that map, counting the new dummy event you're making.


For processing it as a number in an event or any other need while the game is running:
You can set a control variable to a script and then add:

$gameMap.events().length

if im not mistaken this should numerically add the number of events on the current map you're in, remember to reset this variable before re-counting on another map.

corrected to proper syntax
But
$gameMap.events().length
this can only check the number of events on the map where the player is located, not the number of events on the specified map.
For example the player is on map 1, but I want to check the number of events on map 3
  1. Load the json of the map in question
  2. Check the length of the event element.

The async nature of loading files makes the first step a bit difficult.
Perhaps you can scavenge some code from an abandoned plugin I had lying around:

If you know you'll only run the code in a place where 'fs' is available then using that to load will be easier. Checkout out my MoarMaps Helper plugin for an example of how to do that:

Note: While my plugins are aimed at MZ the code for loading map files shouldn't be too different in MV

*hugs*
- Zeriab

Original thread: https://forums.rpgmakerweb.com/threads/how-to-get-the-total-number-of-events-for-a-map.148730/