Status
Not open for further replies.

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
35,913
Reaction score
9,525
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
998
Reaction score
858
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
998
Reaction score
858
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,907
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?
 

EvaarK

Warper
Member
Joined
Jan 17, 2022
Messages
1
Reaction score
0
First Language
Portuguese
Primarily Uses
RMMV
JavaScript:
var alias_sceneBoot_start = Scene_Boot.prototype.start;
Scene_Boot.prototype.start = function() {
    alias_sceneBoot_start.call(this);
    // code goes here
}
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,718
Reaction score
15,848
First Language
English
Primarily Uses
RMMV

@EvaarK, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

ScreenShot_5_26_2022_11_36_32.png
added a Panic gauge to battle. it fills up according to your actions. each character has a different passive that activates once the gauge is full. also once full, a countdown starts and after each action taken, the gauges decreases. with each character, the decrease is different.
Genuinely considering making a thread informing people how to Google.
It's time for Da Update...

Prototyping some overworld abilities. Some of the characters you'll meet on your journey can use special overworld skills to travel around. This can be something like digging holes in the ground or getting hints towards your next objective.

Even more things I made.
Equipping Abilities is very important.
fLhHhZjh.gif

Forum statistics

Threads
122,157
Messages
1,146,890
Members
160,423
Latest member
THORR1
Top