I've got a peculiar issue with my logic. I've set up a behaviour on an object (a particle type thing) that when a certain action triggers should increment a global variable. The problem I'm having is that, sometimes there can be quite a few instances of that object so, when the particular event is triggered on multiple instances at the same time only some of the objects actually increase the global variable.
For example: I've got 3 of this particles in the scene. They all may trigger the event with about half a second time interval between them. So the global variable increases from 3 to 6 after all three particles triggered. Everything is fine. However, let's say I've just created 6 more of those particles, 3 of them trigger the event at the same time (or with extremely short time between them) and the other three trigger with a bit of time in between them. Now the global variable would have gone from 6 to 10 instead of 12 as it should have.
Here's a gif illustrating my issue:
[[I would've embedded it but apparently I can't post pictures since I just registered my account here... Silly]]
Every time I click on the "bot" thing it spawns 5 of these particles, when they reach the counter, they should increment the global variable by one each and then destroy themselves. They all clearly destroy themselves, but they don't all increment the global variable.
The relevant event is in a behaviour inside the particle itself and looks like this:
+ Flag 2 is on?
- Add 1 to Energy
Flag 2 is a flag I use to tell the particle it's next to the counter. That clearly work since all particles get destroyed as they should.
I've included the mfa file, it requires the Advanced Direction Object extension. The particles in question are in the "Game" scene, under a folder called GameObjects.
Any advice is very much appreciated!
EDIT: Forgot to mention that I use a custom movement on the particle so some solutions might not work, like checking collision between objects.