I think the reason you are getting the issue, is because every time the ammo value (which I assume is the
value variable) is less than 8 you are calling the
power_charge() function . You need to wait for the power bar to refill, before you call the function again.
I've managed to reproduce what you were doing by adding a label to the progress bar, so I could see the ammo count. I used a variable called
_ammo as it made more sense to me.
I moved the ammo check to the
_process() function and added a flag to check if the bar is charging. I've dropped the timer value, so I can see it charging.
I think if you call
set_power_bar it should set the
_ammo value and use the power charge function.
The code has the mouse button test in it and an update to the label, which you can remove. This should work, let me know if it doesn't. You may have to change the
_ammo variable to work with the rest of your project.
var _ammo = 8
var _charging = false
func _process(_delta: float) -> void:
if _ammo < 8 and !_charging:
_charging = true
# check for mouse button
if event is InputEventMouseButton and event.pressed:
if _ammo > 0:
_ammo -= 1
func _update_shots() -> void:
$Label.text = "Shots left = " + str(_ammo)
_ammo = value
value = 0
for i in 10:
value += 10
value = min(value, 100)
# PlayerStats.power_count += 1
_ammo += 1
value = 0
_charging = false