[Solved] Actions seem to affect multiple instances

  • Hi,

    I really don?t 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:

    <img src="https://dl.dropboxusercontent.com/u/4928547/construct_trouble.png" border="0" />

    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. It?s 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?

    thanks

  • Add a 'For each' and it will behave as you expect.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well thanks, it?s working now with the following change:

    <img src="https://dl.dropboxusercontent.com/u/4928547/construct_solved.png" border="0" />

    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 don?t know the reason but I think it?s 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?

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)