• 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 Instance ID doors

X

xorphinindi

Guest
I'm getting a weird error and I can't figure out why.

My game uses a system of electric doors that have a locked and an unlocked state which can be toggled using a computer terminal. This is by use of an in-game menu that calls a script which holds a switch statement. The terminal communicates with a motion sensor object called obj_doorsense separate from obj_door. If the sensor is in the "unlocked" state, the door actually opens when the player approaches it and enters the sensor's vision cone. My room has 4 doors, each with an accompanying sensor.

The problem is that I'm getting an error while using the terminal to unlock a door, saying:

"Variable <unknown_object>.<unknown variable>(100047, -2147483648) not set before reading it.
at gml_Script_scr_systemsMenuD (line 42) - if(obj_doorsense.shopRoom_lock.open = true || obj_doorsense.shopRoom_lock.opened = true){"

The line in question is from the menu script within case 3.

It's weird because this is only happening for ONE of the doors. It's even weirder because if I delete the sensor associated with the error, then the error will jump to a different door.

Here's my code:

Relevant stuff from obj_doorsense create event:
Code:
teleRoom_lock  = instance_place(1008, 272, obj_doorsense);
questRoom_lock = instance_place(1232, 272, obj_doorsense);
saveRoom_lock  = instance_place(1008, 688, obj_doorsense);
shopRoom_lock  = instance_place(1232, 688, obj_doorsense);
Menu object create event:
Code:
menu[0] = "Command";
menu[1] = "Teleporter Room";
menu[2] = "Save Station";
menu[3] = "Shop Room";
menu[4] = "Return";

space = 32;
mpos = 0;
Menu script called by selecting a menu option:
Code:
switch (mpos){
    case 0:{
        // command room door lock
        if(obj_doorsense.questRoom_lock.open = true || obj_doorsense.questRoom_lock.opened = true){
           obj_doorsense.questRoom_lock.open = false;
           obj_doorsense.questRoom_lock.opened = false;
           obj_doorsense.questRoom_lock.image_index = 0;
        }
        else{
            obj_doorsense.questRoom_lock.open = true;
        }
        break;
    }
    case 1:{
        // teleporter room door lock
        if(obj_doorsense.teleRoom_lock.open = true || obj_doorsense.teleRoom_lock.opened = true){
           obj_doorsense.teleRoom_lock.open = false;
           obj_doorsense.teleRoom_lock.opened = false;
           obj_doorsense.teleRoom_lock.image_index = 0;
        }
        else{
            obj_doorsense.teleRoom_lock.open = true;
        }
        break;
    }
    
    case 2:{
        // save room door lock
        if(obj_doorsense.saveRoom_lock.open = true || obj_doorsense.saveRoom_lock.opened = true){
           obj_doorsense.saveRoom_lock.open = false;
           obj_doorsense.saveRoom_lock.opened = false;
           obj_doorsense.saveRoom_lock.image_index = 0;
        }
        else{
            obj_doorsense.saveRoom_lock.open = true;
        }
        break;
    }
    
    case 3:{
        // shop room door lock
        if(obj_doorsense.shopRoom_lock.open = true || obj_doorsense.shopRoom_lock.opened = true){
           obj_doorsense.shopRoom_lock.open = false;
           obj_doorsense.shopRoom_lock.opened = false;
           obj_doorsense.shopRoom_lock.image_index = 0;
        }
        else{
            obj_doorsense.shopRoom_lock.open = true;
        }
        break;
    }
    
    case 4:{
        // Return
        instance_create(x, y, obj_menuD);
        with(obj_systemsMenuD){
            instance_destroy();
        }
        break;
    }
}
Thanks in advance for any help.
 

Simon Gust

Member
It could be that instance_place() misses the door objects or that this object checking is spawning in before the doors are even there (execution order error).
instance_place returns noone if it doesn't find anything so an error is produced.

What you can do is check the instance creation order in the room editor or call instance_create() and spawn the doors yourself.
Code:
teleRoom_lock  = instance_create(1008, 272, obj_doorsense);
questRoom_lock = instance_create(1232, 272, obj_doorsense);
saveRoom_lock  = instance_create(1008, 688, obj_doorsense);
shopRoom_lock  = instance_create(1232, 688, obj_doorsense);
 
Top