Legacy GM [From Heartbeast Tutorial]Global Variables won't work.(Need Help)

S

Sugor

Guest
I'm at HearthBeast tutorial and i'm already on the Loading episode and at the first Saving episode
case 0:
room_goto(obj_player_stats.previous_room);
works perfectly fine!...
but then when i followed the Loading episode
it gives me a error that the instance (obj_player_stats.previous_room); doesn't exist
This is

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_pause_menu:

Unable to find any instance for object index '7' name 'obj_player_stats'
at gml_Object_obj_pause_menu_StepNormalEvent_1 (line 25) - room_goto (obj_player_stats.previous_room);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_pause_menu_StepNormalEvent_1 (line 25)
 

Binsk

Member
I don't know the tutorial but 1) that is an instance variable not a global variable and 2) the error is saying the instance you are trying to pull the variable from doesn't exist.

Make sure you have one placed in the room.
 
S

Sugor

Guest
uhmm
This is from my create: script
Code:
/// Initialize the player's stats

hp = 5;
maxhp = hp;
stamina = 10;
maxstamina = stamina;
expr = 0;
maxexpr = 10;
level = 1;
attack = 1;
previous_room = room;

// Get the Player's Location
if (instance_exists(obj_player)){
    player_xstart = obj_player.x;
    player_ystart = obj_player.y;
    }else{
        player_xstart = 0;
        player_ystart = 0;
    }
    
room_start_action = NEW_ROOM;
and the my script from executing the coe
Code:
/// Control the Menu
if (alarm[0] <= 0 ) {
     if (obj_input.down_key) {
        if (menu_index < array_length_1d(option)-1){
            menu_index++;
        } else {
            menu_index = 0;
        }
        alarm[0] = room_speed/6;
     }
    
     if (obj_input.up_key){
        if (menu_index > 0) {
            menu_index--;
        } else {
            menu_index = array_length_1d(option)-1;   
        }
        alarm[0] = room_speed/6;
     }
        
     if (obj_input.dash_key){
        switch (menu_index){   

       case 0:
        room_goto(obj_input.previous_room);
            break;
       case 1:
            game_end();
            break;
                
        default:
            break;
        }
        obj_input.dash_key  = false;
    }
}
 
H

Homunculus

Guest
If you can't properly read the error messages you are going to have a hard time both debugging and asking for help here. You are not posting the code where the error actually happens.

From the error itself looks like you are trying to call the previous_room variable from an instance of obj_player_stats, but no instance of that object exists when the error happens. The code is run in the step event of obj_pause_menu, so it would be helpful to at least see that piece of code and get some info about obj_player_stats.
 
S

Sugor

Guest
I apologize i really don't know how to explain it on comments. i'm not good at socializing
If you can't properly read the error messages you are going to have a hard time both debugging and asking for help here. You are not posting the code where the error actually happens.
From the error itself looks like you are trying to call the previous_room variable from an instance of obj_player_stats, but no instance of that object exists when the error happens. The code is run in the step event of obj_pause_menu, so it would be helpful to at least see that piece of code and get some info about obj_player_stats.
Thats actually my point. but i tried everything i know... its still didn't work i really don't know what it is
 
H

Homunculus

Guest
When are you creating the obj_player_stats instance to begin with? Maybe it's an instance that's supposed to be in every room of your game but you forgot to set it to persistent or something like this...
 

Binsk

Member
We're programmers, none of us know how to socialize.

Joking aside, do you have an object named obj_player_stats in your game? If so, make sure you have it placed in your room. That is all we are trying to say.

As a friendly note, however, if you don't know how a piece of code works, DON'T USE IT. Make sure you understand the code before you use it. This problem is an example as to why.
 
S

Sugor

Guest
We're programmers, none of us know how to socialize.

Joking aside, do you have an object named obj_player_stats in your game? If so, make sure you have it placed in your room. That is all we are trying to say.

As a friendly note, however, if you don't know how a piece of code works, DON'T USE IT. Make sure you understand the code before you use it. This problem is an example as to why.
I do have the obj_player_stats inside the room
and i used something like
if(instance_exists(obj_player_stats)) {
obj_player_stats.persistent = true;
}

maybe i'll give the project file so u can see it through i think if wanted to help if no its okay.
 
Top