0 votes

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.isactionpressed("uifire") and canfire:
var bulletinstance = bullet.instance()
bullet
instance.position = $BulletPoint.getglobalposition()
bulletinstance.rotationdegrees = rotationdegrees
bullet
instance.applyimpulse(Vector2(), Vector2(bulletspeed, 0).rotated(rotation))
gettree().getroot().addchild(bulletinstance)
ammo -= 1
print("Taking 1% ammo")
canfire = false
yield(get
tree().createtimer(firerate), "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****

in Engine by (15 points)

1 Answer

0 votes
Best answer

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).

by (1,742 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.