[SOLVED] Game crashes when actor dies (upon collision)?

Auzzy Waffles

  • Posts: 26
In my game, the main character/actor dies if it collides with any other actor. When testing this on the iPhone simulator, the game crashes 9 out of 10 times upon collision with any actor. When testing this on flash player, 7 out of 10 times i get a pop-up telling me "TypeError: Error #1009: Cannot access a property or method of a null object reference." upon collision with any actor. What does this mean, and how can i stop this? Much appreciated.

« Last Edit: August 25, 2014, 06:12:33 pm by Innes »

Innes

  • *
  • Posts: 1960
This means that you are carrying out a test or action on an object that no longer exists.

For example, maybe you are trying to change (or read) the value of an attribute associated with an actor that has already been killed.

The #1009 error is saying that Stencyl cannot access the property (e.g. attribute) or method (e.g. event) of an object that does not exist.

Typically, this occurs when you detect a collision, kill an actor, then try to read some information from that actor or trigger an event for that actor. You need to make sure that you have read the information or triggered the event before the actor is killed. An easy workaround for this is to use the [<self> is alive] block in an [if] test, before accessing the property / method. However, you will probably want to make sure that you don't kill the actor until after accessing the property / method, otherwise you may experience other problems (for example, a score may not update because the actor has been killed, so the bonus value can't be read from that actor).
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

Auzzy Waffles

  • Posts: 26
Thank you!! I managed to fix it with your tips.

Innes

  • *
  • Posts: 1960
Great; I've amended the topic title to reflect the 'solved' status.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

Murph725

  • Posts: 1
I have the same problem and your explanation doesn't make sense to me, help!

Innes

  • *
  • Posts: 1960
Hi, can you explain which part doesn't make sense? It's difficult to offer further a advice without more information from you.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.