Bashar al Hot Bod
Member
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:
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:
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.
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;
}
}
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;
}
___________________________________________
############################################################################################
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.