Home > Software design >  Godot how do i erase characters using backspace
Godot how do i erase characters using backspace

Time:01-02

I'm trying to program a textbox that I can write in using the keyboard; but the backspace key doesn't erase text, nothing happens when I press it.

extends Node2D


onready var Text = $Panel/RichTextLabel


# Called when the node enters the scene tree for the first time.
func _ready():
    pass # Replace with function body.


func _unhandled_input(event):
    if event is InputEventKey:
        if event.pressed == true:
            match event.scancode:
                KEY_A:
                    Text.append_bbcode("a")
                KEY_BACKSPACE:
                    if Text.get_total_character_count() > 0:
                        print("0")
                        Text.visible_characters -= 1
    pass

CodePudding user response:

Godot already has a built-in TextEdit node that does exactly what you are trying to do.

  • Related