Exits region event

manu5

  • Posts: 27
There seems to be a bug with exits region event because it gets called multiple times. Maybe some bug with recycled actors. I made a very simple test scenario  (complete game file also attached) and here is the log output:

[LOG] [Flash] Universal#initScreen(162): Stage Width: 640
[LOG] [Flash] Universal#initScreen(163): Stage Height: 480
[LOG] [Flash] Universal#initScreen(164): Screen Width: 640
[LOG] [Flash] Universal#initScreen(165): Screen Height: 480
[LOG] [Flash] Universal#initScreen(166): Screen DPI: 72
[LOG] [Flash] Universal#initScreen(314): Max Scale: 1
[LOG] [Flash] Universal#initScreen(315): Engine Scale: 1x
[LOG] [Flash] Universal#initScreen(556): Scale X: 1
[LOG] [Flash] Universal#initScreen(557): Scale Y: 1
[LOG] [Flash] scripts.ActorEvents_0#init(64): 1 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 1 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 1 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 2 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 2 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 2 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 1 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 1 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 1 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 2 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 2 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 2 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 1 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 1 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 1 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 2 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 2 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 2 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 1 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 1 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 1 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 2 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 2 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 2 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 1 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 1 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 1 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 2 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 2 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 2 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 1 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 1 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 1 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 2 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 2 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 2 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 2 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 1 created
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(80): 1 exits area
[LOG] [Flash] scripts.ActorEvents_0#init(72): 1 exits screen
[LOG] [Flash] scripts.ActorEvents_0#init(67): 1 killed
[LOG] [Flash] scripts.ActorEvents_0#init(64): 2 created

sdieters

  • Posts: 2068
in not sure, but I think he gets killed by instance since he never enters the last created region, and thus by instance is told that he exits the region.
My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

manu5

  • Posts: 27
I think I found it. So such "actor leaves region" events are basically functions, that are added to a region. Each region has a list of them, and every time, when any actor crosses the border, all functions in the list gets executed with the actual actor that crossed the border as a parameter. In the function, Stencyl creates it first checks if this is the same actor we added the listener for. But since Stencyl recycles actors, thinks it is the previously killed actor. And when an actor is killed, its listener functions are not removed from the region's list but when recycled (created again) it adds the same function again so it gets executed multiple times. You can solve it by adding the listener to the scene, not to the actor or deleting the region the listener is attached to every time you kill the actor.

sdieters

  • Posts: 2068
Not really. stencyl only recycles actors if you tell him to. And regions do not have functions, since you never add anything to them. You have to see a region as an extra collision trigger.

But as I was writing this explanation I saw the problem. You keep killing the actor, but the region remains there. Try removing the last created region before killing the actor itself.

My new profile is TheIndieStation.
When you see a recent post with this name, i'm probably using my phone. So dont mind any typo's =p

manu5

  • Posts: 27
Well since 3.0 Stencyl always recycles actors.

And the point is when actor created (or recycled in fact) it adds the same event listener again without removing the listeners of previously killed actors so that's why it gets executed multiple times.

gamegirlxl

  • Posts: 713
I don't really trust regions.  It might be better to not use them.

You could try doing something like: (was_in is a Boolean, and in_range is a Boolean returning function, which has been set to be a square with height and width of 20, and a top left corner set at (20, 20) )

When created-
   Set was_in to false
Always-
   If was_in AND NOT in_range
      Trace actor+" exited"
   Set was_in to in_range
in_range-
   If 20<x<40 AND 20<y<40
      return true
   Otherwise return false