My code to dictionary

extends Node2D
var player_words = [] # the players words
var introduction = “Welcome to Silly songs!\n\nLets write a strange tune.\nGive me some words and I’ll write some prose.\n\n\nLets start with a noun.”

var template = [
{
“prompt”:[“a noun”, “a feeling”, “a verb”, “adjective”, “another noun”, “another feeling”, “another noun”],
“song”:“Early one morning %s always %s would have been %s the %s %s with the %s %s.”
},
{
“prompt”:[“a noun”, “a place”, “a verb” , “a noun”],
“song”:“There is %s in %s, they call it %s %s.”
}
]

var current_story

func _ready():
randomize()
current_story = template [randi() % template.size()]
$Blackboard/StoryText.text = introduction
$Blackboard/TextBox.grab_focus()
$Blackboard/TextureButton/ButtonTextOK.text = “Enter”

func _on_TextureButton_pressed():
if is_story_done():
get_tree().reload_current_scene()
else:
_on_TextBox_text_entered($Blackboard/TextBox.get_text())

func _on_TextBox_text_entered(new_text):
if new_text != “”:
player_words.append(new_text)
$Blackboard/StoryText.text = new_text
$Blackboard/TextBox.clear()
check_player_word_length()

func is_story_done():
return player_words.size() == current_story.prompt.size()

func prompt_player():
$Blackboard/StoryText.text = ("Can I have " + current_story.prompt[player_words.size()] + “, please?”)

func check_player_word_length():
if is_story_done():
tell_story()
else:
prompt_player()

func tell_story():
$Blackboard/StoryText.text = current_story.song % player_words
end_game()

func end_game():
$Blackboard/TextBox.queue_free()
$Blackboard/TextureButton/ButtonTextOK.text = “Again”

Privacy & Terms