• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Obj_Player Not Set Before Reading

am new to Gms2 and i cant find how to fix this.
I keep Getting Obj_Player Not Set Before Reading But I have Obj_Player At The Top of the list


MY Code is this Obj_PLayer

P_Stats = {

Hp : 100,
HpMax : 100,

};

Obj_camera On Draw Gui

draw_text(View_Camera_Width - 300, View_Camera_Height - 300, P_Stats.Hp);
^^^
Also Get the same bug with my lava on collision = Obj_Player with the top one Off

P_Stats.Hp -= 1;


i tryed to add Obj_Player to a diff room then Added Goto_Next but it still didnt work
 

Attachments

O.Stogden

Member
The error is because you reference "P_Stats" in your obj_camera object, but P_Stats is made in the obj_player object. So the obj_camera is returning an error saying it doesn't know what P_Stats is.

If you want the camera to reference it, you need to make "P_Stats" a global variable/struct.
 

O.Stogden

Member
var P_Stats is a temporary variable, it gets deleted at the end of the code block. It takes the least amount of resources.

P_Stats is an instance variable, it lasts forever, but only the object itself can reference it.

global.P_Stats would make it permanent, and means it can be accessed from any object, but takes up a little more resources than the other 2. Nothing noticeable however.

This manual page may be of use for you to read through https://manual.yoyogames.com/#t=GameMaker_Language/GML_Overview/Variables_And_Variable_Scope.htm
 
If you want the camera to reference it, you need to make "P_Stats" a global variable/struct.
[/QUOTE]

So Can i Make it Like This Global.P_Stats = {

All Stats Here??

}
 

O.Stogden

Member
global.P_Stats rather than Global.P_Stats yes.

This means any object in your game can read your stats you put in there.
 
Top