• 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!

Legacy GM [SOLVED]Variable not set before reading it help

E

Edeyz

Guest
Sorry if the answer is obvious or something but I cant work out why its doing this.

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Other Event: Room Start
for object obj_HUDParentShipDesign:

Variable obj_HUDShipDesignBack.numuberOfHUDObjects(100014, -2147483648) not set before reading it.
at gml_Object_obj_HUDParentShipDesign_StartRoomEvent_1 (line 4) - for (i = 0; i < numuberOfHUDObjects; i ++)
############################################################################################

I have 2 events in obj_HUDParentShipDesign the first is a

CREATE:
///Generates the array
numuberOfHUDObjects = 0;
Code:
with obj_HUDParentShipDesign
    {
    if object_index != other.object_index
        {
        other.HUDShipDesign[other.numuberOfHUDObjects, 0] = object_index; //The object Index
        other.HUDShipDesign[other.numuberOfHUDObjects, 1] = x;            //X
        other.HUDShipDesign[other.numuberOfHUDObjects, 2] = y;            //Y
        other.numuberOfHUDObjects ++;
        }
    }
The second is a
ROOM START:
Code:
///Loads the HUD
if room = rm_shipDesign
    {
    for (i = 0; i < numuberOfHUDObjects; i ++)
        {
        instance_create(HUDShipDesign[i, 1],HUDShipDesign[i, 2],HUDShipDesign[i, 0]) //Creates the HUD Item
        }
    }
obj_HUDShipDesignBack is child of obj_HUDParentShipDesign(Parent object) but seams to be using a line of code it should have nothing to do with.

Thank you

Edeyz
 

toxigames

Member
Since numuberOfHUDObjects = 0; is run in obj_HUDParentShipDesign create event and is parent to obj_HUDShipDesignBack, the obj_HUDShipDesignBack inherits everything from obj_HUDParentShipDesign including the create event. The exception is of course if you have added an create event to obj_HUDShipDesignBack but is not calling the event_inherited(); function. That would lead to variable numuberOfHUDObjects being non existing in create event of obj_HUDShipDesignBack and thus this error would happen.

So: check if obj_HUDShipDesignBack has a create event and if so check if there is an event_inherited(); function being called there. If not, the solution would be to either add event_inherited(); to the create event or delete the create event entirely from obj_HUDShipDesignBack.

I hope this helps you.
 
Top