[Solved] Actions seem to affect multiple instances

Get help using Construct 2

Post » Mon Jan 13, 2014 10:27 pm

Hi,

I really dont understand this... I have 2 instances of an "enemy" type. There is another object that can collide with them. When they overlap (collide) the "is Hit" boolean of the enemy is set to true. When the collider object collides with both enemies at the same time something strange is happening. I have this in my enemy event-sheet:



When I step over the action "subtract 1 from hitCount" I was expecting only ONE enemy loosing a "hit point"... the enemy whoose instance I am currently stepping through. Instead both enemies are loosing a "hit point" at the same step in the debugger. Its like the "enemy" in the action means "all enemy instances" instead of the one instance I am currently in.

In addition to that the function "PushBack" is only called for one of the instances. I have no clue what is happening there. What am I doing wrong?

thanksGumbo2014-01-17 10:46:05
B
5
S
1
Posts: 19
Reputation: 463

Post » Mon Jan 13, 2014 10:53 pm

Add a 'For each' and it will behave as you expect.
ImageImageImage
B
71
S
22
G
249
Posts: 3,763
Reputation: 138,577

Post » Fri Jan 17, 2014 10:29 am

Well thanks, its working now with the following change:



But I really want to understand this completely. The event filters all enemies that are "is Hit" and performs the actions on them. This means that internally something like 'For each' is done by construct (For each enemy that is "is Hit" perform 'Subtract 1 from hitCount'). This is working for normal actions but not for 'Functions'. I dont know the reason but I think its something like a 'const char*' in C. The pointer points only to the first element of the 'array' so the function is only called with the first of the filtered objects. Does anyone know why I have to use 'for each' for functions but not for normal actions?Gumbo2014-01-17 10:44:11
B
5
S
1
Posts: 19
Reputation: 463

Post » Fri Jan 17, 2014 2:34 pm

It has something to do with how picking is handled I think. The "Function" object is a unique instance, so the call get executed only once with the first UID from the filtered list of enemy. If the "Sprite" object could somehow link itself with the "Function" object, the internal for each would probably take care of the multiple calls. Maybe something on the to-do list ?

Anyhow, an explicit for each works and you implemented it perfectly in tandem with the implicit one.
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests