Load Script after game is loaded

Archimedes

Warper
Member
Joined
May 4, 2016
Messages
3
Reaction score
1
Primarily Uses
For some reason, my code is running before the actual game, and I cannot access the $gameSystem global constructor. I tried this:


(function() {
$gameSystem.onBeforeSave();
})();


Did not work returned: Can not read property 'onBeforeSave' of undefined


Also tried


window.onload(function(){
$gameSystem.onBeforeSave();
})


Same Error,


What is going on? How do execute my code after $gameSystem is loaded.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,430
Reaction score
7,711
First Language
German
Primarily Uses
RMMV
I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.
 

mjshi

Jack of Most Trades
Veteran
Joined
Feb 16, 2013
Messages
969
Reaction score
807
First Language
English
Primarily Uses
N/A
How about adding a check to see if $gameSystem exists?

Code:
if ($gameSystem) {
  // etc...
}
 

Archimedes

Warper
Member
Joined
May 4, 2016
Messages
3
Reaction score
1
Primarily Uses
if ($gameSystem) {
// etc...
}


That wouldn't work because the if statement is being evaluated before $gameSystem is even loaded so of course it won't be defined. And when it is finally loaded that if statement won't run again.
 
Last edited by a moderator:

Archimedes

Warper
Member
Joined
May 4, 2016
Messages
3
Reaction score
1
Primarily Uses
Would it really be that complex? I'm sure i'm not the only scripter that needs this to be pulled off.
 

mjshi

Jack of Most Trades
Veteran
Joined
Feb 16, 2013
Messages
969
Reaction score
807
First Language
English
Primarily Uses
N/A
Oh, it's not complex to hook onto that. Just alias the method/function. What that does is essentially copy the original function (so that you can "call" it again, then you can write your own code below the function. Use "aliasname.call(this)" to call the original function, then add your own code above/below it.

Code:
var aliased_datamanager_function = Datamanager.someFunction;
Datamanager.someFunction = function () {
  aliased_datamanager_function.call(this);
  //etc code that you add
};
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,848
First Language
English
For some reason, my code is running before the actual game, and I cannot access the $gameSystem global constructor. I tried this:



(function() {
$gameSystem.onBeforeSave();
})();


Did not work returned: Can not read property 'onBeforeSave' of undefined


Also tried



window.onload(function(){
$gameSystem.onBeforeSave();
})


Same Error,


What is going on? How do execute my code after $gameSystem is loaded.


Can you explain what your code is doing?
 

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

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

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.

Forum statistics

Threads
106,034
Messages
1,018,446
Members
137,820
Latest member
georg09byron
Top