Global variable not set before reading

Discussion in 'Programming' started by Gamesalive, Aug 13, 2019.

  1. Gamesalive

    Gamesalive Member

    Joined:
    Oct 16, 2018
    Posts:
    11
    Hi,
    I have an issue where the output says my global variable is not set before reading. The variable global.itemHeld is initiated in a separate initiation room by a persistant object. When a new object is created afterwards, it tries to access the variable upon creation. Here is the error:

    for object obj_hold_item:
    global variable name 'itemHeld' index (100072) not set before reading it.
    at gml_Object_obj_hold_item_Create_0 (line 10) - holdItem = ds_grid_get(global.quickslot,global.itemHeld,slot.id);
    ############################################################################################
    --------------------------------------------------------------------------------------------
    stack frame is
    gml_Object_obj_hold_item_Create_0 (line 10)
    called from - gml_Object_obj_player_Create_0 (line 4) - holdItem = instance_create_depth(x,y,-100,obj_hold_item);
    called from - gml_Object_obj_player_controller_Create_0 (line 8) - global.player = instance_create_layer(100,100,"Instances",obj_player);

    I'm not sure whether this is a glitch in GMS2 but I hope not. The room is changed almost immediately after the global.itemHeld is initiated.
    Thanks in advance for any help! I hope this all makes sense ;-)
     
  2. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,180
    Can you show the code where you create /initialize the global variable.
     
  3. Gamesalive

    Gamesalive Member

    Joined:
    Oct 16, 2018
    Posts:
    11
    Here is the line:
    global.itemHeld = item("Empty");

    I think I may have just fixed this, at least temporarily but hopefully not.
    It seemed to be an issue using the create event rather than game start and room start events. Thanks for your help though! I appreciate it! This might help future people to fix this so I'll leave it up.
     

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