Suggestion: change the name of check_player_word_length

check_player_word_length feels like smelly code to me. The function decides what is displayed to the player and causes it to be displayed. The fact that it uses the player word length isn’t particularly relevant. IMHO it should be something like displayDialogue(). This would lend itself to a bit of code that looks like this and doesn’t have any side affects (the side affect of check_player_word_length is it displaying text on the screen)

> extends Node2D
> 
> # member variables
> var playerWords = [] # the words the player enters
> var prompt = ["a name", "a thing", "a feeling"]	
> var story = "Once upon a time a %s ate a %s and felt very %s."
> var instructions = "This game asks some questions and shares a story that you created.  Enter to start."
> 
> 
> func _ready():
> 	clearTextBox()
> 	displayDialogue()
> 
> 
> func clearTextBox():
> 	$Blackboard/TextBox.text = ""
> 
> 
> func displayDialogue():
> 	if playerWords.size() == 0:
> 		tellInstructions()
> 	elif playerWords.size() == prompt.size():
> 		tellStory()
> 	else:
> 		promptPlayer()
> 
> 
> func _on_TextureButton_pressed():
> 	var textBox_text = $Blackboard/TextBox.text
> 	_on_TextBox_text_entered(textBox_text)
> 
> 
> func _on_TextBox_text_entered(new_text):
> 	playerWords.append(new_text)
> 	clearTextBox()
> 	displayDialogue()
> 
> 
> func promptPlayer():
> 	$Blackboard/StoryText.text = "Can I have " + prompt[playerWords.size()] + ", please?"
> 
> 
> func tellStory():
> 	$Blackboard/StoryText.text = story % playerWords
> 
> 
> func tellInstructions():
> 	$Blackboard/StoryText.text = instructions
1 Like

I agree. check_player_word_length sounds like a function that should check something and return a status, not a function that should be adding text to the screen. display_dialog has a nice verby name that more accurately describes what the function does.

Privacy & Terms