Instance variable destroys two not one

  • Hi,

    I have been trying to make a game and along the process I have encountered a bug. Its when an enemy's health (instance variable) < or = to 0 Enemy Destroy than, add 5 to score. The code is in the attachment below.

  • This is the wrong section BTW. You should really post this in the 'How Do I' section.

    Have you used debug to see what value(s) health is holding? It may not be a whole number, due to the way computers calculate numbers, so using one of the usual expressions may help, such as round, Int etc.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • zenox98 I will remember that topics like this are supposed to go in the 'How Do I' section. Health holds 10 health than it goes down to five than zero and than bot instances are destroyed. It remains a whole number no matter how the player hits the enemy. What do you mean [quote:4ay59nv6]usual expressions may help, such as round, Int etc.

  • What about the events that damage the enemy? Maybe you damage both enemies when you hit one. The event you showed would only destroy two enemies if they both have health <= 0.

  • r2cvv There's nothing wrong with the piece of code you've shown... I'd guess the error is somewhere else in the code. Care to share the capx?

  • What about the events that damage the enemy? Maybe you damage both enemies when you hit one. The event you showed would only destroy two enemies if they both have health <= 0.

    ramones Here is the code for the player attacks. Whether it is the first code or the second they will both be destroyed.

  • brunopalermo Ashley I have followed some of ashley's tutorial on how to make an enemy move back & forth.

  • Still you need either to replicate the issue in a new capx if you don't want to publish the current capx, or just go and post your capx so we can investigate it further.

    There is nothing wrong with the few lines of code you've shown so far and we can't guess how you made your project.

    If you fear people stealing your project, don't fear.

    It's not working as intended at the moment anyway, so there's nothing to steal.

  • Kyatric I'll PM you the capx.

  • Just share it here and we all might help... Seriously, nobody is going to steal other people's projects around here... And ideas are overrated anyway.

  • Here is the capx.

    brunopalermo

    Kyatric

  • > What about the events that damage the enemy? Maybe you damage both enemies when you hit one. The event you showed would only destroy two enemies if they both have health <= 0.

    >

    ramones Here is the code for the player attacks. Whether it is the first code or the second they will both be destroyed.

    Right that will damage all enemies. You have to use:

    Player: On collision with Family -> Family: Subtract from health

    or

    Player: On collision with Sprite -> Sprite: Subtract from health

    Use either the Family or the Sprite in both the condition and action. You can't use the family in the condition and the sprite in the action or vice versa.

  • Here...

    [attachment=0:2yovkcje][/attachment:2yovkcje]

    Whenever the player collides with any member of the Enemy family you are damaging all FlyerEnemy and Shooter instances.

    Use: Enemy subtract X from Health

  • brunopalermo Thanks! Your suloution helped me!

  • One last thing... I noticed you wanted the enemies to take different amounts of damage. Instead, you could have the damage fixed and vary the enemy's HP.

    Thus, instead of the bullet causing 2 to the Flyer and 8 to the Shooter, make the Flyer HP 4 times the Shooter's. You'll have the same effect.

    Or you could have the damage taken as an Enemy variable. Whatever works for you.

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