How can I make this if statement loop

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By chimmychim

I am making a top-down shooter also I am new to coding so I will make mistakes but how do I loop this if statement because every time I shoot I loose 1 ammo and I have 6 bullets
and if I use all 6 the if statement gets triggered but it only triggers once then doesn’t work anymore. Sorry I am bad at typing

if Input.is_action_pressed(“ui_fire”) and can_fire:
var bullet_instance = bullet.instance()
bullet_instance.position = $BulletPoint.get_global_position()
bullet_instance.rotation_degrees = rotation_degrees
bullet_instance.apply_impulse(Vector2(), Vector2(bullet_speed, 0).rotated(rotation))
ammo -= 1
print(“Taking 1% ammo”)
can_fire = false
yield(get_tree().create_timer(fire_rate), “timeout”)
can_fire = true
if ammo == 0: #This entire if code is my problem
print(“Notice 0% ammo”)
reload = true
can_fire = false
yield(get_tree().create_timer(reload_speed), “timeout”)
print(“Finished Reload”)
can_fire = true

:bust_in_silhouette: Reply From: Thomas Karcher

The ammo is never set back to 6 (ammo = 6). This should happen next to (or instead of) the line reload = true (not sure whether this line has a purpose anywhere else, but in this part of the code the reload value is never used for anything).

I was super tired when I made that code and pretty much after I sent this question I did the ammo = 6 But this did work and Thank You

chimmychim | 2020-09-15 19:04