System Function to Initialize Custom Functions

Hello again.

I'm at a loss of what's best to do. I need to call my functions that use game objects, and I need them to start when the game loads after the title screen. I can't seem to find a function to use to put my calls inside where this works. 

An example would be using:

if (Input.isPressed('ok')) { console.log('space bar pressed');}I need this to work while the player is walking around, right after the new game, or continue, loads. I just have no idea what to throw it in, or if there is another way to hook a function to an already existing function so it executes on call, only after the game objects load. I've been looking and trying some for a while (nearly 2 days off and on), but without API or documentation it's increasingly difficult.

Everything I try returns null or doesn't start initially on the game load. Example:

(function() { // test key battle if (Input.isPressed('ok')) { console.log('space bar pressed'); }})();...returns null object with error.

I'd imagine an explanation and example would help a lot of newcomers to MV as well, so if anyone answers if they could explain a bit on why, etc. that'd be great.

P.S.

Forgive me on the deleted posts, my questions were redundant to things already answered, some by my own post from some help I got recently. I'll be a bit more careful and clear on my questions as best I can.
Well, I'm going to assume you want this to be active on the map, right? Just alias Game_Map's update function, and have it call your own function to check is a key is pressed. Keep in mind, however, there are 3 keys that are mapped to 'ok'. Enter, Space, and X.
Well, I'm going to assume you want this to be active on the map, right? Just alias Game_Map's update function, and have it call your own function to check is a key is pressed. Keep in mind, however, there are 3 keys that are mapped to 'ok'. Enter, Space, and X.

If you don't mind sharing how to add a key input and name, that'd be great too!

***Edit 2***

Tried this:

var eSystem.Initialize = Game_Map.prototype.update;Game_Map.prototype.update = function() { // test key battle if (Input.isPressed('ok')) { console.log('space bar pressed'); }}Putting var in front of eSystem give an error for the '.' between esystem and initialize. Guess I'm setting it up wrong for eSystem? without var, I can't load levels.... Help?
If you leave it with that code, the map won't update. You aliased the function, but never called the alias. Also, since you're using a local variable to hold the alias, please wrap the code in an anonymous function. That will prevent the alias from becoming a global variable. You had it in an anonymous function in your original post, so it's just a small modification of what you have now.

(function() {var eSystem.Initialize = Game_Map.prototype.update;Game_Map.prototype.update = function() { eSystem.Initialize.call(this); // test key battle if (Input.isPressed('ok')) { console.log('space bar pressed'); }}});As for adding in new keybinds, you can either use my key mapper plugin, or just see how it works.
I edited my post probably right as you were posting yours, but putting 'var' in front gives me an error:

Uncaught SyntaxError: Unexpected token .

if I take var out, then nothing happens when hitting enter/space in the console. Both ways the level does load now though...

this is my entire code, I'd imagine I'm setting up the 'eSystem' wrong (ignore the params, I'm just learning how to use them)?

//=============================================================================// Eilios - System// Eilios_System.js// Version: 1.0.0//=============================================================================var eSystem = eSystem || {};//=============================================================================/*: * @plugindesc v1.0.0 Used for all basic system management in the game. * @author Eilios * * @param Critical Multiplier * @desc critical hit dmg = base damage * this multiplier * Default: 3 * @default 3 * * @param Min Initial TP * @desc Minimum amount of TP a character may have at the start of battle. * Default: 0 * @default 0 * * @param Max Initial TP * @desc Maximum amount of TP a character may have at the start of battle. * Default: 25 * @default 25 * * @help More when it comes */(function() { // set up the paramaters eSystem.Parameters = PluginManager.parameters('Eilios_System'); eSystem.Param = eSystem.Param || {}; eSystem.Param.CriticalMultiplier = Number(eSystem.Parameters['Critical Multiplier']); eSystem.Param.MaxInitialTP = Number(eSystem.Parameters['Max Initial TP']); eSystem.Param.MinInitialTP = Number(eSystem.Parameters['Min Initial TP']); (function() { var eSystem.Initialize = Game_Map.prototype.update; Game_Map.prototype.update = function() { eSystem.Initialize.call(this); // test key battle if (Input.isPressed('ok')) { console.log('space bar pressed'); } } });})();Added eSystem.Initialize = eSystem.Initialize || {}; after eSystem.Param = eSystem.Param || {}; in the code, but still no response from the console when hitting the key.
Two things.

1) Why do you have an anonymous function inside another anonymous function?

2) You're declaring eSystem outside of your first anonymous function and later you use "var eSystem" again to create another eSystem variable inside your second anonymous function.

You should rather try something like this:

Code:
var eSystem = eSystem || {};(function() {	// set up the paramaters	eSystem.Parameters = PluginManager.parameters('Eilios_System');	eSystem.Param = eSystem.Param || {};	eSystem.Param.CriticalMultiplier = Number(eSystem.Parameters['Critical Multiplier']);	eSystem.Param.MaxInitialTP = Number(eSystem.Parameters['Max Initial TP']);	eSystem.Param.MinInitialTP = Number(eSystem.Parameters['Min Initial TP']);	        eSystem.Initialize = Game_Map.prototype.update;		Game_Map.prototype.update = function() {				eSystem.Initialize.call(this);			// test key battle			if (Input.isPressed('ok')) {				console.log('space bar pressed');			}		}	})();
1. I thought it was meant to wrap it inside of what was already there. xD I was wondering lol.

2. Now the link to the next map won't load. this was the problem I kept having when removing var before the eSystem.Initialize.
Sorry for the double post, but another related problem came up. 

Links to other maps don't work now. See above.
Ahh, I hadn't noticed you already had them in an anonymous function, my mistake. Turns out I made several mistakes when writing that, sorry. 

What do you mean the link to the next map won't load?
I have an event placed on the map that warps the player to another map, with the code like is in the last post with code for this thread, it just doesn't warp to the next map, it just freezes the player. Key press does work, however. if I comment out the alias and game_map parts, the event works fine.

var eSystem = eSystem || {};(function() { // set up the paramaters eSystem.Parameters = PluginManager.parameters('Eilios_System'); eSystem.Param = eSystem.Param || {}; eSystem.Param.CriticalMultiplier = Number(eSystem.Parameters['Critical Multiplier']); eSystem.Param.MaxInitialTP = Number(eSystem.Parameters['Max Initial TP']); eSystem.Param.MinInitialTP = Number(eSystem.Parameters['Min Initial TP']); eSystem.Initialize = Game_Map.prototype.update; Game_Map.prototype.update = function() { eSystem.Initialize.call(this); // test key battle if (Input.isPressed('ok')) { console.log('space bar pressed'); } } })();I'm using YED's plugin for tiled, could that have anything to do with it? I wouldn't see how, since if it's using it it's aliased, and if it isn't it shouldn't matter and I don't see anything in it for the game map update function specifically, but I'm still new so who knows? Just to add as well, no errors, it just freezes the player.
It was because I wasn't including sceneActive like it had in the original function.

Game_Map.prototype.update = function(sceneActive) { eSystem.Initialize.call(this, sceneActive);Works now.

Original thread: https://forums.rpgmakerweb.com/threads/system-function-to-initialize-custom-functions.51166/