JS-Noob and the instant plugin failure

Wyzai

Warper
Member
Joined
Jan 10, 2016
Messages
4
Reaction score
1
First Language
Finnish
I'm a noob who's trying to learn javascript through RMMV. So far I have worked through the issues I encountered with the aid of multiple tutorials, but now I have a problem and I can't for the life of me find any mention of something like this no matter how much I google.

My plugins crash instantly whenever I start the game.

The lines causing the problem work fine if used manually through the developer console in the middle of the game.

I imagine there's something simple I'm missing, but I can't figure out what and so far I haven't found a tutorial that mentions something like this.

Just to prove my point I made a 1 line plugin. When I playtest the game and hit F8. I am instantly told by the console: ".../js/plugins/1test.js:1 Uncaught TypeError: Cannot read property 'actor' of null"

if I type it manually?

"$gameActors.actor(1).hp" results in "100", which is the hp of the main character.

This is the entirety of the plugin:

$gameActors.actor(1).hp
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,676
First Language
German
Primarily Uses
RMMV
Your plugin is probably executed before the game is started.


But $gameActors only exist after either "new game" or loading of a savefile.


You need to make sure that the plugin is only executed after a game is started, not during the title screen.


I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.


(Plugin Support is for existing plugins, not when you try to write it)
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
$gameActors gets created the first time during Scene_Boot.start, because MV actually creates a new game, before entering Scene_Title.
 

Wyzai

Warper
Member
Joined
Jan 10, 2016
Messages
4
Reaction score
1
First Language
Finnish
I figured it was something like that.

As I said, I'm a noob.

How do I tell the plugin to wait until something is loaded?

Any kind of workaround would be greatly appreciated.

Edit:

Actually it seems this worked. No error message on playtest.

while ($gameActors === undefined) {

setTimeout(

$gameActors.actor(1).hp

, 1000) }

 

Edit#2: No, not really. Seems I can't put functions (or at least multiple functions) inside that.
 
Last edited by a moderator:

Kino

EIS Game Dev
Veteran
Joined
Nov 27, 2015
Messages
556
Reaction score
794
First Language
English
Primarily Uses
RMMV
For the rest are you trying to just get the character hp, yes? 
Question is what time do you want to check it? Usually the best place would be during a scene.
As Iavra said, $gameActors doesn't exist until Scene_Boot.start.
So if you wanted to check Actor HP at the start of the game in the console, or modify it.

//Alias Scene_Bootvar Scene_Boot_start = Scene_Boot.prototype.start;Scene_Boot.prototype.start = function() {//Lets Scene boot run it's original codeScene_Boot_start.call(this);//Outputs game actor 1 to the consoleconsole.log($gameActors.actor(1));//Output game actor hp?console.log($gameActors.actor(1).hp);//Update gameActor hp$gameActors.actor(1).hp = 600;};So during the Scene_Boot, the hp will be updated to 600 in this case. The actor object, and actor hp will also appear in the console.
 
Last edited by a moderator:

Wyzai

Warper
Member
Joined
Jan 10, 2016
Messages
4
Reaction score
1
First Language
Finnish
For the rest are you trying to just get the character hp, yes? 

Question is what time do you want to check it? Usually the best place would be during a scene.

As Iavra said, $gameActors doesn't exist until Scene_Boot.start.

So if you wanted to check Actor HP at the start of the game in the console, or modify it.

//Alias Scene_Bootvar Scene_Boot_start = Scene_Boot.prototype.start;Scene_Boot.prototype.start = function() {//Lets Scene boot run it's original codeScene_Boot_start.call(this);//Outputs game actor 1 to the consoleconsole.log($gameActors.actor(1));//Output game actor hp?console.log($gameActors.actor(1).hp);//Update gameActor hp$gameActors.actor(1).hp = 600;};So during the Scene_Boot, the hp will be updated to 600 in this case. The actor object, and actor hp will also appear in the console.
I'm not actually trying to accomplish anything specific. I just seemed to hit that brick wall no matter what I tried.

But in essence the point of this test script was just to check if my character has a hp value and this seems to have done it. I'll have to put some time into using this new information. A thousand thanks!

EDIT: in case someone else uses this solution, it appears you cannot have multiple lines like "Scene_Boot_start.call(this)". Had the test plugin active and tried making another that uses the same starting time and got an error about the call length.
 
Last edited by a moderator:

Kino

EIS Game Dev
Veteran
Joined
Nov 27, 2015
Messages
556
Reaction score
794
First Language
English
Primarily Uses
RMMV
To answer that, the reason why is because, the code is running itself again when you do another Scene_Boot...call(this).

It reruns a functions code, so if you had multiple..it executes itself multiple times, until it reaches the maximum stack size, or call length. It can be helpful, if you want to use recursion, but I wouldn't use it in this case.
 

Wyzai

Warper
Member
Joined
Jan 10, 2016
Messages
4
Reaction score
1
First Language
Finnish
if someone has a better solution, it is welcome. Altough, for now, this one is working. As long as I use each version only once, I can get my plugin to work as intended.
 

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

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,074
Members
137,578
Latest member
JamesLightning
Top