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.

asked Mar 7 in Engine by CardboardPow (55 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"
answered Mar 8 by jgodfrey (4,382 points)
selected Mar 19 by CardboardPow

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 How to use this Q&A? before posting your first questions.