#Game crashes when the player touches an enemy

1 messages · Page 1 of 1 (latest)

visual thicket
#

Hi, I am making a top-down view game, it's very simple: enemies spawn randomly and follow the player, so the player has to shoot them. If an enemy touches the player, you lose. But sometimes when they collide, the game crashes before the game over screen.
I noticed that apparently the bug doesn't happen when the player isn't moving when they collide, but other than that it's very inconsistent

vocal spindle
#

-4 means noone

#

which means that instance_place didn't find an instance

#

just add an extra if _EnemyTouching != noone

visual thicket
#

ok thanks

vocal spindle
#

actually

#

replace that if place_meeting

#

with the if !=noone check

visual thicket
#

ok

vocal spindle
#

no reason to calculate it twice

#

or maybe not?

do you move your object inside here?

#

idk

#

depends on your code

visual thicket
#

it worked, thx

vocal spindle
# visual thicket yes

that's probably why then
your _EnemyTouching becomes "outdated" because you moved
so your place_meeting check is checking at a different spot than _enemyTouching

#

if you don't use _EnemyTouching inside that if
i'd recommend moving it down to after you moved

#

so that it's up to date with the position