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

Discussion in 'Programming' started by Sugor, May 28, 2019.

  1. Sugor

    Sugor Member

    Joined:
    May 28, 2019
    Posts:
    17
    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)
     
  2. Binsk

    Binsk Member

    Joined:
    Jun 22, 2016
    Posts:
    542
    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.
     
  3. Sugor

    Sugor Member

    Joined:
    May 28, 2019
    Posts:
    17
    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;
        }
    }
    
     
  4. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    616
    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.
     
  5. Sugor

    Sugor Member

    Joined:
    May 28, 2019
    Posts:
    17
    I apologize i really don't know how to explain it on comments. i'm not good at socializing
    Thats actually my point. but i tried everything i know... its still didn't work i really don't know what it is
     
  6. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    616
    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...
     
  7. Binsk

    Binsk Member

    Joined:
    Jun 22, 2016
    Posts:
    542
    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.
     
  8. Sugor

    Sugor Member

    Joined:
    May 28, 2019
    Posts:
    17
    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.
     
  9. Sugor

    Sugor Member

    Joined:
    May 28, 2019
    Posts:
    17
    Or maybe i'll find another way to make a save and load.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice