Help with bullet

in a game where a machine gun is used for example … how can I check that every single bullet does its duty? I mean … hitting the target takes away the desired energy and all subsequent commands I want to add … be it impact effects sounds or whatever …
because I’m having severe difficulties … in the sense that however long I can use the for each function and how long I can put an object variable on the bullet that is a boolean hit … enemies sometimes lose energy but don’t die … and that’s it that it happens to only one enemy that all the rest of enemies acquire this unwanted power of immortality …

with this code I am afraid that the hit variable will be changed to all the bullets that have been created and not just to one
I’m wrong??? at the moment I create an object by assigning it a variable string = 0 when I then press FIRE for each bullet it will be with that variable 0 … is that correct? if during the journey ammo1 changes … and I have 20 in the game … all 20 will change ???

As a note, don’t delete an object and then reference it. That will cause errors in the way the game runs.

The event with the condition Ammo1 is in collision with Enemy will filter or reduce the list of Ammo1 and Enemy objects. This reduced list is what is used in the actions or in subevents when you refer to Ammo1 or Enemy.

This will do what you’re after, and is more efficient because it only repeats over the Ammo1 objects that have collided with an Enemy object (instead of all Ammo1 object as you had it):

forgive me maybe in the translation something has been lost I did not understand …

in your screenshoot how the bullet disappears from the game if you don’t delete it ???

The last action of the bottom event deletes Ammo1.

oops sorry … I think I understand … if I kill the bullet first in my screenshot it is clear that what comes after cannot refer to it … right ??

Yes, that’s correct. You can not reference something that doesn’t exist.


i no have in my list sign “-=” where have you take it??

It’s the subtract modifier. You can change the way the modifiers are displayed in GDevelop settings.

what is a difference??? is the same?

Yes, it’s just displayed differently.

1 Like

thanks i try your way … every time you talk you teach me 7 things … it would be nice to be able to contact you instantly … thanks again