Text doubling in RichTextLabel

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

I’m trying trying to print some text to a richtextlabel every time I hit the space key, the issue is that whenever I hit the space key, it prints the text twice. The code is running in a scene with just a richtextlabel node with the following code.

extends RichTextLabel
var letter = "This is the text"


func _input(event):
	if event is InputEventKey and event.scancode == KEY_SPACE and not event.echo:
		self.add_text(letter)
:bust_in_silhouette: Reply From: Wakatta

That’s because the event happens twice

  • once for when pressed
  • and another for when released

Update to this.

extends RichTextLabel
var letter = "This is the text"


func _input(event):
    if event is InputEventKey and event.pressed:
        if event.scancode == KEY_SPACE and not event.echo:
            self.add_text(letter)