Clearing text box challenge

gdt_s02_lineedit__text_from_the_player

#1

I initially thought that you could clear the text by setting the box = null, that was horribly mistaken. Update For some reason it didn’t occur to me that we’re calling one function from another and we only needed to put the clearing code in once. I’ve corrected my main project file.

extends Node2D

var prompt = ["person", "ate", "blue", "dragon", "toe", "tired"]
var story = "Once upon a time, there was a %s who %s a %s %s.  Afterwards she hurt her %s and became very %s."

func _ready():
	$Blackboard/StoryText.text = story % prompt

func _on_TextureButton_pressed():
	var new_text = $Blackboard/TextBox.get_text()
	_on_TextBox_text_entered(new_text)
	$Blackboard/TextBox.text = ""

func _on_TextBox_text_entered(new_text):
	$Blackboard/StoryText.text = new_text
	$Blackboard/TextBox.text = ""

#2

$Blackboard/TextBox.clear() also works for clearing the text box.


#3

2nd Runthrough:
changes to code: image
I also put the text over my button: image
@JoVzla#0588 mentioned in the chat that he couldn’t click the button when he did this because it was selecting the RichTextLabel. @kevin.carbonaro#2045 pointed out that the mouse property in the inspector for RichTextLabel needed to be set to pass or ignore to make it work. image I did the same thing on mine.


#4

I found clear and one less variable easier in the pressed func.

Nice tip about the mouse filter.


#5

Thanks for the tip about the mouse filter. I saw it last night while reading the forums and tonight while messing around with my game, it turned out to be just what I needed :c)


#6

Thanks for this! I played around with code for a good while trying to use clear() and came very close to your solution but not close enough. I finally gave up and watched the video, only to discover an empty string instead :joy::joy:


#7

Thanks! I couldn’t figure out how to get void clear() to work but then looked into how .get_text and .set_text worked because the former was used earlier and found out that $Blackboard/TextBox.set_text("") also works to clear by resetting the text box to an empty string but I will remember this for the future!