It's because the window layer will generally not have been added by the end of the scene's
create method. The scene creates its display objects only after the map data has loaded:
JavaScript:
Scene_Map.prototype.onMapLoaded = function() {
if (this._transfer) {
$gamePlayer.performTransfer();
}
this.createDisplayObjects();
};
Instead, you should patch the
createDisplayObjects method, which gets called when the database has loaded. E.g.
JavaScript:
// Private scope to avoid naming clashes
(function() {
// Store original method
var _Scene_Map_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
// Define override
Scene_Map.prototype.createDisplayObjects = function() {
// Invoke stored method
_Scene_Map_createDisplayObjects.apply(this, arguments);
// Run extra code
this.createMapWindow();
};
})();
Also, note that a patch/alias, like I've used here, usually lets you write less code than a full override and gives a better chance of compatibility with other plugins~
Edit: I didn't see your edit before, sorry.
😴
EDIT:
Changed the two functions in my code. Not getting the error, but I am not getting any window displayed.
JavaScript:
Scene_Map.prototype.create = function() {
Scene_Base.prototype.create.call(this);
this._transfer = $gamePlayer.isTransferring();
var mapId = this._transfer ? $gamePlayer.newMapId() : $gameMap.mapId();
DataManager.loadMapData(mapId);
this.createWindowLayer()
this.createMapWindow();
};
// snip //
The window layer is re-created when the map data loads, which is why this doesn't work.
createDisplayObjects is the way to go!
👋