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

SOLVED Help with issue related to persistence and event ordering

I have an issue that I believe may be due to the ordering of events, but am not sure. The game I’m working on has the player moving through various rooms, and depending on which door the player enters the room from, where they spawn in that room will change. All the rooms are persistent, and the player is persistent as well.

Each spawn point contains a variable called “number”, which is set through the instance's individual creation code in the inspector. This number is used to link certain spawn points to certain doors.

Code similar to this is in the step event of every door:
Code:
if(keyboard_check_pressed(ord("E")))
    {
        if(open == true)
        {
            global.toSpawnPoint = 1;
            room_goto(roomKitchen);
            global.newRoom = true;
        } 
}
global.toSpawnPoint is set so that the player knows which spawnPoint to spawn at when global.newRoom is true. This code runs in the players step event:

Code:
if(global.newRoom == true)
{
        var i;
        for(i = 0; i < instance_number(oSpawnPoint); i++)
        {
            if(instance_find(oSpawnPoint, i).number == global.toSpawnPoint)
     targetSpawnPoint = instance_find(oSpawnPoint, i);
        }
    
        x = targetSpawnPoint.x;
        y = targetSpawnPoint.y;
        global.newRoom = false;
}
I get the following error when *returning* to certain rooms:

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

Variable <unknown_object>.number(100043, -2147483648) not set before reading it.
at gml_Object_oPlayer_Step_0 (line 7) - if(instance_find(oSpawnPoint, i).number == global.toSpawnPoint) targetSpawnPoint = instance_find(oSpawnPoint, i);
############################################################################################
gml_Object_oPlayer_Step_0 (line 7)

My initial assumption was that the number variable no longer sets upon re-entering a persistent room, but some rooms work fine so I don’t think that’s the issue. The number also defaults to 1 in the create event of the spawnPoint, so I don’t know why the number would ever not be set. Unless the persistent player’s step event continues to run before the new room has a chance to run create/creation events. Although I would assume even if that was the case, the rooms being persistent would solve that issue.

Any help would be appreciated.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Make sure you're creating this instance after all instances of oSpawnPoint. You can define this in the Layer Properties of the layer your instances are on in the room editor.
 
This may have been an engine bug? I just deleted the spawn points and placed new ones and it works fine now. That or I overlooked something the first time I placed them. Either way it seems there's no issue now.
 
Top