0 votes

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)
Godot version 3.3.4
in Engine by (12 points)

1 Answer

0 votes

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)
by (4,972 points)
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.