Textbox help needed

Godot Version

Godot 4.x


I am working on a text box system for my game and im trying to make it so that if a button is pressed, the text box hides and disables. Help needed please!

extends CanvasLayer

@onready var textbox_container = $TextboxContainer
@onready var start = $TextboxContainer/MarginContainer/HBoxContainer/Start
@onready var text = $TextboxContainer/MarginContainer/HBoxContainer/Text
@onready var end = $TextboxContainer/MarginContainer/HBoxContainer/End
@onready var charname = $TextboxContainer/MarginContainer/HBoxContainer/Name
@onready var animation_player = $“…/AnimationPlayer”

func Textbox(currentname,Talktext):
charname.text = str(currentname)
text.text = str(Talktext)

func show_textbox():

func hide_textbox():
if Input.is_action_just_pressed(“Jump”):

func _ready():

can just make the text boxes textboxes.visible=false to hide and textboxes.visible=true to show it

A couple of issues I see.
The _ready() function runs only once and that is when the node is first attached to the tree.
So any code you put in there runs once.

You have if Input.is_action_just_pressed(“Jump”): inside the hide_textbox() function. Apart from the one time that function runs coming from _ready() it won’t get run again. So it will never see any input.
In order to poll for keypresses (or other input) you need to check inside a game loop; something that runs repeatedly.
In Godot most commonly that is the _physics_process() function. That function runs once per frame.
So you put Input.is_action_just_pressed(“Jump”): inside the _physics_process():


It seems strange to me to hide the textbox on the jump action but that is not necessarily an issue.

When you post here you will see a menubar across the top with various menu options such as B (for bold text) and I (for italic text).
The one that looks like this </> is the code tag. Use that when posting code and the code will keep its formatting. The formatting is very necessary for others to debug your code.