RMMV Uncaught TypeError: Cannot read property 'members' of null

MekroKnight

Villager
Member
Joined
Dec 17, 2020
Messages
7
Reaction score
2
First Language
Turkish
Primarily Uses
RMMV
Hi, i'm trying to make a plugin that shows the party learder's health in the screen. Well i'm trying to check if party leader's health is equals to 450 and when i try to check this with plugin i am getting this error:

error.png

And when i'm trying to do this with console, i'm not getting any errors. The code works perfectly, btw here is the code:

JavaScript:
if ($gameParty.members()[0]._hp == 450){
    console.log("450")
}

Why am i getting an error while i running this code with plugin? (Btw sorry for my bad english)
 

MekroKnight

Villager
Member
Joined
Dec 17, 2020
Messages
7
Reaction score
2
First Language
Turkish
Primarily Uses
RMMV
By the way if you are wondering the plugin code, here it is:
JavaScript:
(function() {
    if ($gameParty.members()[0]._hp == 450){
        console.log("450")
    }
})();
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,341
Reaction score
8,077
First Language
German
Primarily Uses
RMMV
"of NULL" means that the object which has the function or data requested does not exist.

in this context, it most likely means that either the party or the members are not yet defined at the moment your code is executed.

the party and quite a number of other object like variables are only defined at "new game", not at the title screen or before that.
So most likely you created that function in a context where it is executed before the "new game" is started.
 

MekroKnight

Villager
Member
Joined
Dec 17, 2020
Messages
7
Reaction score
2
First Language
Turkish
Primarily Uses
RMMV
"of NULL" means that the object which has the function or data requested does not exist.

in this context, it most likely means that either the party or the members are not yet defined at the moment your code is executed.

the party and quite a number of other object like variables are only defined at "new game", not at the title screen or before that.
So most likely you created that function in a context where it is executed before the "new game" is started.
Thank you about that but, how am i going to fix this issue? Like, am i should check if player is not in the main menu or something? And how am i going to do that?
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,881
Reaction score
1,355
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi there!

You need to know when you will execute this function.
Hi, i'm trying to make a plugin that shows the party learder's health in the screen.
So it seems kind of a Hud? So you want to show it on the scene map? Scene battle?

If so, you need to take a look at one of these scenes and understand the flow of it. After that, you will know when you will call your function.

You can also, just to be safe, made a check before using it:
JavaScript:
if($gameParty.exists()){
do your code...
}
 

MekroKnight

Villager
Member
Joined
Dec 17, 2020
Messages
7
Reaction score
2
First Language
Turkish
Primarily Uses
RMMV
Hi there!

You need to know when you will execute this function.

So it seems kind of a Hud? So you want to show it on the scene map? Scene battle?

If so, you need to take a look at one of these scenes and understand the flow of it. After that, you will know when you will call your function.

You can also, just to be safe, made a check before using it:
JavaScript:
if($gameParty.exists()){
do your code...
}
Yes i want to show an image when player is on scene map but i couldn't do it. Can you help me about this please? And of course i should check the player's health too. For an example:
JavaScript:
if (// scene map){
    if ($gameParty.members()[0]._hp == 450){
            // shows the health of the party leader with image
    }
}
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,881
Reaction score
1,355
First Language
Portuguese - Br
Primarily Uses
RMMZ
Well, that's kinda complicated to say exactly what you have to do, but you have to take a look at the Scene Map class and see where you can create your HUD. So by the name of the functions you can have a hint of it. For example:

JavaScript:
Scene_Map.prototype.createDisplayObjects = function() {
    this.createSpriteset();
    this.createMapNameWindow();
    this.createWindowLayer();
    this.createAllWindows();
};

You can alias that function and create your hud before everything. Or you can use the AllWindows. But that is an example.
So you check: if game party exists && $gameParty.members()[0]._hp == 450...
do your code.

You can also use $gameParty.leader() that will always get the first member of the party($gameParty.members()[0])
 

MekroKnight

Villager
Member
Joined
Dec 17, 2020
Messages
7
Reaction score
2
First Language
Turkish
Primarily Uses
RMMV
Well, that's kinda complicated to say exactly what you have to do, but you have to take a look at the Scene Map class and see where you can create your HUD. So by the name of the functions you can have a hint of it. For example:

JavaScript:
Scene_Map.prototype.createDisplayObjects = function() {
    this.createSpriteset();
    this.createMapNameWindow();
    this.createWindowLayer();
    this.createAllWindows();
};

You can alias that function and create your hud before everything. Or you can use the AllWindows. But that is an example.
So you check: if game party exists && $gameParty.members()[0]._hp == 450...
do your code.

You can also use $gameParty.leader() that will always get the first member of the party($gameParty.members()[0])
Well yeah this is a little bit complicated i'll try this out thank you but, is there any way for just checking if the scene is scene map?
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,881
Reaction score
1,355
First Language
Portuguese - Br
Primarily Uses
RMMZ
You don't need to check if the scene is "Scene Map" if you create your hud on the scene map.
That's why you first have to understand the RM code or understand it as you do your plugins.
In this case, you should take a look at the Scene Map class and see how they implement, for example, the Game Timer or the Map Name Window.

Then you follow the references until you understand how both appear on the map.

After that, you will know for sure how you can put your hud there ^^
 

MekroKnight

Villager
Member
Joined
Dec 17, 2020
Messages
7
Reaction score
2
First Language
Turkish
Primarily Uses
RMMV
You don't need to check if the scene is "Scene Map" if you create your hud on the scene map.
That's why you first have to understand the RM code or understand it as you do your plugins.
In this case, you should take a look at the Scene Map class and see how they implement, for example, the Game Timer or the Map Name Window.

Then you follow the references until you understand how both appear on the map.

After that, you will know for sure how you can put your hud there ^^
Thanks for the advice! :)
 

Latest Threads

Latest Profile Posts

My Game Development Livestream

Of course, so, someone had covid at work today and I was exposed to them, so, I'm stuck at home for...TWO WEEKS!
oh god I'm going to die
AAAAAAAAi.png
Kind of relieved that I had medibang installed when I need to edit Sprite I was about to download gimp but I remember I had medibang installed lol

Forum statistics

Threads
110,370
Messages
1,052,677
Members
143,403
Latest member
prismat83
Top