System Function to Initialize Custom Functions

Eilios

Veteran
Veteran
Joined
Nov 13, 2015
Messages
58
Reaction score
2
First Language
English
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.
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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.
 

Eilios

Veteran
Veteran
Joined
Nov 13, 2015
Messages
58
Reaction score
2
First Language
English
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?
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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.
 

Eilios

Veteran
Veteran
Joined
Nov 13, 2015
Messages
58
Reaction score
2
First Language
English
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.
 
Last edited by a moderator:

kiriseo

Veteran
Veteran
Joined
Oct 27, 2015
Messages
245
Reaction score
82
First Language
German
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');			}		}	})();
 

Eilios

Veteran
Veteran
Joined
Nov 13, 2015
Messages
58
Reaction score
2
First Language
English
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.
 
Last edited by a moderator:

Eilios

Veteran
Veteran
Joined
Nov 13, 2015
Messages
58
Reaction score
2
First Language
English
Sorry for the double post, but another related problem came up. 

Links to other maps don't work now. See above.
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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?
 

Eilios

Veteran
Veteran
Joined
Nov 13, 2015
Messages
58
Reaction score
2
First Language
English
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.
 
Last edited by a moderator:

Eilios

Veteran
Veteran
Joined
Nov 13, 2015
Messages
58
Reaction score
2
First Language
English
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,018
Messages
1,018,357
Members
137,803
Latest member
andrewcole
Top