[Solved] Adding to variable stops with two collisions

Hi! Good day! I have been trying to create a game with a machinegun with two barrels and I made it so that a variable counts each time a bullet hits a target. It works quite well when one bullet hits. But if both bullets hit a target the counting variable just stops and doesn’t count anymore. Yet the target’s health still goes down properly though.Tried looking into the debugger but there is nothing I can see going on that seems to be doing it.
So I tried alternating the shots so that one bullet is slightly ahead of the other, it seems to work with a 0.1 second buffer before creating the second bullet and a 0.3 second time interval between firing, but at 0.2 second, it acts up again. And this alternating thing is kinda not nice to look at. Simultaneous shots would really be preferred. I tried searching the forum for similar cases but I couldn’t seem to find any. Is there a certain limit or “cooldown” needed for repeatedly accessing variables? Or is it a limitation with collisions? Or is there something else that I’m missing perhaps?

Attached are the codes in question.

Because you need to right click any event choose add and add for each object
In it select your object you want to damage and there you make all your events for damaging object

Look how this HP bar goes
And it accounts damage for each bullet
Even so same units fire same bullets so bazooka soldiers fire same bazooka bullet object


1 Like

Alright. It’s working now. Thank you so much!
I’ve been trying to avoid using for each since I placed a trigger once in the collision condition hoping to avoid one hit registering as more than one. And I’ve read somewhere that trigger once doesn’t work well with for each. But I suppose it’s okay in this case? Or should I just get rid of the trigger once?

General tip
If something is working as you want with trigger once
Have trigger once on it since it is your first line of defense against FPS drop

And yeah by definition trigger once should not work inside for each loop
I even seen mods who work on this engine say that
Yet for some reason it works in some cases
Especially if you play sound FOR EACH bullet
You just need there trigger once
IDK why it works but it does and that is all i care and all you should care

1 Like

lol! omg! That’s interesting to know. I’ll be sure to keep that in mind.
Thank you again. I really appreciate it.

If event is executing constantly it eats up your performance
Like animation change (it does not eat a lot)
But faster you learn to shove in trigger once to everything longer you will be free of most FPS drop issues
For example you can create HP bars for each enemy on your map
IF you do it without trigger once
OR without taking into account objects which are NOT linked to any HP bar already
You will lag your game
Sometimes it is noticeable after a min or so
So you always want to prevent events from executing constantly

Same with bullets
You should have event to delete bullets if they idk exist for 5 secs or longer or whatever you adjust time to your needs
If they are 1000 pixels away from player
Cause if they keep traveling they will simply start to lag your game

1 Like