Calling a Scene_Map function from an event

I want to run some function in Scene_Map from an event's script call, but the way I'm doing it now probably isn't the right way to do things.

Right now, I have the event set a global variable to true, and Scene_Map's constantly checking if this global variable is true. If it is, then it'll call some function.
Code:
SceneManager._scene.method();
Does this function need to belong to Scene_Map? Design-wise, it would be better to make it part of your plugin API and call that, instead of going the ugly way and directly accessing the scene (OO-wise, the event shouldn't know about the surrounding scene, though sometimes that's the best option).
Does this function need to belong to Scene_Map?
I think so. I've basically been working on a Scene_CustomBattle, and events push that scene whenever an encounter starts.

Now I want to integrate it into Scene_Map itself instead of transferring the player to a new scene. It'll be affecting .update, adding sprites to .children, and so on, so I think I do need to do it this way, right?
So, it's an action battle system? Because, if it's a new scene, you should just use "SceneManager.push(sceneClass)". I haven't done an ABS so far, but i would probably hook into "Scene_Map.prototype.create", store a reference to "this" (the scene) and clear the reference during "Scene_Map.prototype.terminate". This way, you have the scene referenced from your plugin and can work in there, instead of adding functions to the scene itself.

If you need to add something to an existing class, make sure to prefix it with your own name to make it unique to avoid incompatibilities with other plugins. Also only do this with functions, that you want to be editable by other plugins. Private stuff should always be kept inside the plugin's anonymous function to support encapsulation.
I want to run some function in Scene_Map from an event's script call, but the way I'm doing it now probably isn't the right way to do things.


Right now, I have the event set a global variable to true, and Scene_Map's constantly checking if this global variable is true. If it is, then it'll call some function.
That isn't a bad way to do it. Player transfer does that. So does calling a menu when pressing X.


The general idea is that you just tell the map that you want something done, and it's up to the map to figure out how to do it.

Original thread: https://forums.rpgmakerweb.com/threads/calling-a-scene_map-function-from-an-event.54751/