Warning: $dataMap.meta not available in event test mode

I'm messing around with Foreground.js (one of the Kodokawa plugins) at the moment, which lets you have a second parallax layer above everything else, and is set up using meta tags in a map's "Note" box.

There's a bug with it though: it causes an error when trying to use the event test mode (right-click on an event command -> Test). In this case:

TypeError: Cannot read property 'fgName' of undefinedHaving a look at the plugin we can see where the error occurs:

  Game_Map.prototype.setupForeground = function() {    this._foregroundName = $dataMap.meta.fgName || '';    this._foregroundZero = ImageManager.isZeroForeground(this._foregroundName);    this._foregroundLoopX = !!$dataMap.meta.fgLoopX;    this._foregroundLoopY = !!$dataMap.meta.fgLoopY;    this._foregroundSx = Number($dataMap.meta.fgSx) || 0;    this._foregroundSy = Number($dataMap.meta.fgSy) || 0;    this._foregroundX = 0;    this._foregroundY = 0;  };All the meta data being retrieved has fallbacks, but the $dataMap.meta object itself isn't available in event test mode! This mode just uses an empty map that's generated on the fly, and clearly it wasn't seen necessary to initialize this particular object.

My solution in this case is to add this line at the top of the method:

if (!$dataMap.meta) $dataMap.meta = {};This ensures that there is at least an empty object available so it doesn't throw errors when you try to read properties from it. But I think this is something that should be fixed in the engine itself - if you have a look at rpg_managers.js it has this method:

DataManager.makeEmptyMap = function() { $dataMap = {}; $dataMap.data = []; $dataMap.events = []; $dataMap.width = 100; $dataMap.height = 100; $dataMap.scrollType = 3;}; All it needs is an extra line with $dataMap.meta = {};

So anyway, this is just kinda a word of warning for anyone creating plugins: be sure to try out event test mode (I guess this may also apply to battle test mode depending on what the plugin does) and make sure it's working before you release your script, you might run into an unexpected error that doesn't occur normally. Otherwise it might be a pain in the ass for your users.
Personally, i would always parse notetags myself and not rely on the metamodel, but in case of a third-party plugin, i would probably do it the same way you did (although i never do event test, since all my game consists of is a test map with a few events, anyway).
how about something like this...

/*😠plugindesc set default map for event test instead of using blank map which could throw errors<DEFMAPEVENTTEST>@author Estriole@param Default Map@desc Default Map id for event test@default 1@helpjust for testing*/var EST = EST || {};EST.DefaultMapEventTest = EST.DefaultMapEventTest || {};EST.DefaultMapEventTest.param = $plugins.filter(function(p) {    return p.description.contains('<DEFMAPEVENTTEST>'); })[0].parameters;EST.DefaultMapEventTest.defMapId = Number(EST.DefaultMapEventTest.param['Default Map']);var est_event_test_fix_make_empty_map = DataManager.makeEmptyMap;DataManager.makeEmptyMap = function() {    if(this.isEventTest()) return this.loadMapData(EST.DefaultMapEventTest.defMapId);    est_event_test_fix_make_empty_map.call(this);};we can change the plugin parameter before hit event test...

still using Editor Test Event is not a good move i think. since the editor only pass some data from the event...

when i try having some event that read event comment (without those code above). it crash... (edit2: after another test...

crash is not because of event. but i have code to look for map note... so this problem is only for reading map note)

since it only pass some event command in Test_Event.json

i try setting this event sequence:

> comment:

<extra_fix_size: [16,12]>

<size_trigger>

> show text :You step on the trap switch...

> show animation , arrow special (wait)

> show text : Actor 1(7) Ugghhh...

when event testing... i open Test_Event.json... and the result is shocking:

[{"code":101,"indent":0,"parameters":["",0,0,2]},{"code":401,"indent":0,"parameters":["You step on the trap switch..."]}]it only contain that... so... i think we must not use the event test in the first place...

edit... sorry... my mistake... i only right click on one entry on event page... i don't know we should block all of it...

when i block all of event sequence:

[{"code":108,"indent":0,"parameters":["<extra_fix_size: [16,12]>"]},{"code":408,"indent":0,"parameters":["<size_trigger>"]},{"code":101,"indent":0,"parameters":["",0,0,2]},{"code":401,"indent":0,"parameters":["You step on the trap switch..."]},{"code":212,"indent":0,"parameters":[0,29,true]},{"code":101,"indent":0,"parameters":["Actor1",7,0,2]},{"code":401,"indent":0,"parameters":["Ugghh..."]},{"code":123,"indent":0,"parameters":["A",0]}but still no event id / map id.

Original thread: https://forums.rpgmakerweb.com/threads/warning-datamap-meta-not-available-in-event-test-mode.49167/