Please help, collision crashing game.

limpet76

Member
Haven't been doing gamemaker too long, however I have a problem with my coding. This is the code for the enemy:
STEP
"if collision_line(x,y,obTimb.x,obTimb.y,obWall,1,0)
{
move_snap(0,0)
}
else
{
mp_potential_step(obTimb.x,obTimb.y,4,1)
}"

Then this is the code on the player:
COLLISION WITH ENEMY

"hp -= 5
audio_play_sound(sndShooting,1,0)
if hp <= 0
{
global.gameEnd = true
obTimb.visible = false
room_goto(roomGameOver)
audio_play_sound(sndPlayerHit,1,0)
}"

I am getting an ERROR That looks like this whenever an enemy kills the player:

"FATAL ERROR in
action number 1
of Step Event0
for object obZomb:

Unable to find any instance for object index '0' name 'obTimb'
at gml_Object_obZomb_StepNormalEvent_1 (line 1) - if collision_line(x,y,obTimb.x,obTimb.y,obWall,1,0)"

Any help would be appreciated
 

chamaeleon

Member
Haven't been doing gamemaker too long, however I have a problem with my coding. This is the code for the enemy:
STEP
"if collision_line(x,y,obTimb.x,obTimb.y,obWall,1,0)
{
move_snap(0,0)
}
else
{
mp_potential_step(obTimb.x,obTimb.y,4,1)
}"

Then this is the code on the player:
COLLISION WITH ENEMY

"hp -= 5
audio_play_sound(sndShooting,1,0)
if hp <= 0
{
global.gameEnd = true
obTimb.visible = false
room_goto(roomGameOver)
audio_play_sound(sndPlayerHit,1,0)
}"

I am getting an ERROR That looks like this whenever an enemy kills the player:

"FATAL ERROR in
action number 1
of Step Event0
for object obZomb:

Unable to find any instance for object index '0' name 'obTimb'
at gml_Object_obZomb_StepNormalEvent_1 (line 1) - if collision_line(x,y,obTimb.x,obTimb.y,obWall,1,0)"

Any help would be appreciated
1. Define and explain what a killed player is as implemented in your code.
2. Ensure you have an instance of an object in the room before you attempt to use any of its variables or properties.
3. Stop using object names as if they are instances, use instances instead. Just because you can does not mean it is a very good practice, and you need to understand the implications.
 

limpet76

Member
1. Define and explain what a killed player is as implemented in your code.
2. Ensure you have an instance of an object in the room before you attempt to use any of its variables or properties.
3. Stop using object names as if they are instances, use instances instead. Just because you can does not mean it is a very good practice, and you need to understand the implications.
Sir you have confused me.
 

TsukaYuriko

Q&A Spawn Camper
Forum Staff
Moderator
As the error message says - Unable to find any instance for object index '0' name 'obTimb' - there is no instance of obTimb. You're trying to access the variables of an instance of it. It doesn't exist -> crash. You're probably destroying it somewhere and the code that needs it to exist isn't checking whether it exists via instance_exists beforehand.
 
Well, your missing some code or something because the error is saying that obTimb is missing but I don't see in the code where you may be removing it. my suggestion, simply:

"if instance_exists(objTimb) && collision_line(x,y,obTimb.x,obTimb.y,obWall,1,0)"
 

limpet76

Member
As the error message says - Unable to find any instance for object index '0' name 'obTimb' - there is no instance of obTimb. You're trying to access the variables of an instance of it. It doesn't exist -> crash. You're probably destroying it somewhere and the code that needs it to exist isn't checking whether it exists via instance_exists beforehand.
Problem is, my players not being destroyed, checked for that in the code first.
 

limpet76

Member
Well, your missing some code or something because the error is saying that obTimb is missing but I don't see in the code where you may be removing it. my suggestion, simply:

"if instance_exists(objTimb) && collision_line(x,y,obTimb.x,obTimb.y,obWall,1,0)"
Ends up doing this
FATAL ERROR in
action number 1
of Step Event0
for object obZomb:

Unable to find any instance for object index '0' name 'obTimb'
at gml_Object_obZomb_StepNormalEvent_1 (line 7) - mp_potential_step(obTimb.x,obTimb.y,4,1)
 

TsukaYuriko

Q&A Spawn Camper
Forum Staff
Moderator
If the player exists, this error message will not be shown. Therefore, it either does not exist yet or does not exist anymore - which of the two is the case is not something we can tell you without seeing all relevant code.

Ends up doing this
FATAL ERROR in
action number 1
of Step Event0
for object obZomb:

Unable to find any instance for object index '0' name 'obTimb'
at gml_Object_obZomb_StepNormalEvent_1 (line 7) - mp_potential_step(obTimb.x,obTimb.y,4,1)
objTimb is not obTimb. This should have raised a compiler error. Are you using an ancient version of GameMaker with the game option to treat uninitialized variables as 0, by any chance?
 

limpet76

Member
If the player exists, this error message will not be shown. Therefore, it either does not exist yet or does not exist anymore - which of the two is the case is not something we can tell you without seeing all relevant code.


objTimb is not obTimb. This should have raised a compiler error. Are you using an ancient version of GameMaker with the game option to treat uninitialized variables as 0, by any chance?
I saw objTimb and changed it to obTimb in the code dw. Using V1.4 of GameMaker
 
Oh yea I had a typo my bad... But yea, anywhere you use obTimb you need to check if it exists, BUT I have a feeling you are accidentally deleting it somehow without realizing, or you have some race condition going on where you are destroying things to go to the next room but you are destroying the obTimb before the object that it's inside of and so it's triggering an error.
 

limpet76

Member
Oh yea I had a typo my bad... But yea, anywhere you use obTimb you need to check if it exists, BUT I have a feeling you are accidentally deleting it somehow without realizing, or you have some race condition going on where you are destroying things to go to the next room but you are destroying the obTimb before the object that it's inside of and so it's triggering an error.
Anyway I can link the game file so people can have a look?
 

TsukaYuriko

Q&A Spawn Camper
Forum Staff
Moderator
No real need for that - output debug messages whenever instances of obTimb are created or destroyed, and also output whenever the game thinks it doesn't exist. This alongside some break points in debug mode should lead you to where you're accidentally destroying it.
 
Top