How do I make sure the EndLevel does not load twice?
I thought by setting up a bool would work, but apparently I’m missing something.
The action is bound to the mouse left click and if clicking very fast, no matter what I do, every now and then EndLevel gets loaded twice.
beginning, meaning right after LeftMouseButton? or after the first branch?
the delays are just my failed attempts at trying to make this work. No other purpose
Okay when he does not have ammo and you click will go to the false branch
The solution is when you press the left mouse (I suggest making it an action map and assigning a mouse click)
Make a branch for the variable(Game Over) will prevent it from working twice
so setting and resetting the gameover variable, works for the first part. if user still has bullets → game is not over as soon as the game is over and reaches EndLevel → set the bool to true → this will prevent the mouse click from firing again.
However, once EndLevel widget is loaded… whether the player finished or not, when I load the next level or restart the level, the do once gate seems to be closed and the player can no longer shoot. I tried setting the variable to false again, but it did not work.
To complicate matters even more, in PC on EventBeginPlay I have a DisableInput, which gets re-enabled when the HUD loads. (This part was working fine before) Not sure if this is what’s causing the input lock or the DoOnce not resetting the gate.
Now on subsequent levels, or if I redirect the user to the MainMenu and start playing the 1st level again, the input is locked
(during the same game session)
Is seems to be working… but why?
I’m trying to understand the logic… Why, by adding another branch before the one that is checking for bullets works??
Will need to test it more and make sure EndLevel doesn’t load twice again, but as of right now it seems to be ok.
@Admiral-0
if you don’t mind, can you please dumb it down for me. Why is this new branch not redundant??? Isn’t doing the same thing as the next one???
It’s straightforward logic, every time you press the key you are checking if the game is over or not
then you determine which path code should take
by default, the Gameover variable has a false value then you change it with some conditions
I suggest you learn more about basic programming, especially the theoretical part there is a lot of essential things to know, and this will help you to make a better code structure
and more logical
thanks for helping. I really appreciate it.
I get it now. The reason I kind of got confused was because I had 2 check twice whether the user had bullets left or not. (Just in case the bullet fired was the last the player had). So every time I would end up on the False branch twice when that was the case.
I get it now, by setting the gameover var and adding a branch before all that it stops the flow and only 1 branch of the hasAmmo will ever execute, even on the last bullet.