0 votes

I am creating a FPS game, for the gui I have a text label that tells the player how much ammo they have left.

func _process(_delta):
if reloading:
    ammo_label.text = ("Reloading...")
else:
    ammo_label.text = (str(current_ammo) + " / " + str(clip_size))

I tried multiple things such as using a placeholder. when ever I run it I get the error that says

Invalid set index 'text' (on base: 'String') with value of type 'String'.

I am at a loss of what I am supposed to try next so I figured that someone else might have ran into a similar problem.

in Engine by (57 points)

1 Answer

+2 votes
Best answer

Assuming your ammo_label variable has a proper reference to your Label node, then this will work:

ammo_label.text = "Reloading"
by (19,270 points)
selected by

Though, really, the syntax you show works OK too (but you don't the need the outer parenthesis in either case). With that in mind, I'd guess that your ammo_label variable doesn't hold a valid reference to your Label node.

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 Frequently asked questions and 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 [email protected] with your username.