How to code this?

so I’m trying to make a shooting game for myself but when you shoot the enemy i don’t want him to fall down right there i want the player to have to shoot a certain amount of times like lets say 3 times and then fall down how would i code that is that even possible?

Hi @narutothenoob3, at it’s simplest you would have to create a variable lets call this “enemyHealth”, and set this to the maximum health allowed. Then whenever you deal damage, you lower this number by the damage dealt, update the health counter and check to see if it’s health, after the damage is taken, is “lower than or equal to 0” if this is true “delete the enemy”. And there you have it, a simple health system.

Below I have added an example, though this is a bit complex as I made this as a test for myself. If you’re new to programming it might be a bit hard to summize how I’ve implemented it there as it has a bunch of extra code for stuff, but perhaps intresting to look at after you have made one yourself.

I’d recommend starting with a very simple version yourself; Just 1 enemy, and a variable representing it’s health (with a text item that shows it), and deleting the enemy if the health is equal to or below 0.

After this if you feel like you’re up for it, mess around with the code below a bit. Change some values, predict what you think will happen, then see what actually happens and figure out why.

Short Explanation of the complex code:

  • In essence I’m still using the same method, but using a list to keep track of all my enemies and their Health variables instead, so that I can have multiple enemies and different health values.

  • There are 2 seperate lists one indicating the enemy itself, one for their Health variable;

  • By adding or removing the corrosponding enemy and it’s health at the same time, I can be sure that their index in each list is always the same.

  • Using the “index of (select item here) in list (select list here)” block I can find this index by passing in the enemy and searching the enemy list;

  • Now using the found index I can lookup the enemies Health by looking at "item (found index here) of list enemiesCurrentHealth.

From there on out I do the same things as described in the simple version (most of the complex looking stuff is just to create randomness in a nice and intuitive manner, so dont worry to much about that).

Hope to have helped, if you have questions or struggle with the simpler version don’t worry, just let me know and I’ll be happy to help you along!