Textbox activation not working, help wanted!

Godot Version

4.x

Question

Ive set up a script where if my player character has entered this area2d and a button has been pressed, a textbox would appear, and on the subsequent click, the textbox would hide. Am i doing something wrong?

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"

@onready var state

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

func show_textbox():
	animation_player.play("textbox_open")

func hide_textbox():
	animation_player.play_backwards("textbox_open")
		
func _ready():
	state = 0
	visible = false

func _on_area_entered(body):
	if Input.is_action_pressed("Confirm") and state == 0 and body == $"../../..":
		visible = true
		Textbox("jane doe","hi")
		state = 1
	elif Input.is_action_pressed("Confirm") and state == 1:
		visible = false

The area_entered signal is only emitted once when an area enters and if the Confirm action is not being pressed nothing will happen. You’ll need to check if the Confirm action is being pressed in _process() and do your logic there.

1 Like

This is the best i could do. Although this doesn’t work either, i feel like i am in the right direction. thank you!

func _on_area_2d_body_entered(body):
	if body == $"../../..":
		state = 1
	else:
		pass


func _physics_process(delta):
	if Input.is_action_pressed("Confirm") and state == 1:
		visible = true
		Textbox("joe mama","sugma balls")
		state = 2
	elif Input.is_action_pressed("Confirm") and state == 2:
		visible = false
		

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.