1 remove a node from the scene tree with queue_free()
2 restart the game with reload_current_scene()
3 learn to use return to get information from a function to the one that called it
After watching (learning outcomes)…
Allow the player to restart the game once the story's done!
(Unique Video Reference: 6_LL_GDT)
We would love to know…
What you found good about this lecture?
What we could do better?
Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…
instead of reloading scene I used show() and hide(). I think your way is better if you want to reset the entire scene (i.e. a larger project with many nodes).
the end slide here has get_tree.reload_current_scene() - i realise its just powerpoint but get_tree needs to be a method or it wont work and is unrecognised.
Hi,
I am going through the same lesson right now but the line get_tree().reload_current_scene() doesn’t work for me, the scene doesn’t seem to reload at all as the Line Editor never shows up again and nothing seems to to reloaded/reactivated. I used a break point and the line does execute with no exceptions. Any idea what it could be here?
here is the code:
extends Control
onready var DisplayText: Node = $VBoxContainer/DisplayText
onready var PlayerText: Node = $VBoxContainer/HBoxContainer/PlayerText
var words: Array
var prompts: Array = ["verb","adjective","adjective"]
var story = "the sad monk went %s and then became %s when he ended his journey he became %s"
func _ready():
DisplayText.text = "Welcome to Looney Lips "
check_words_input()
func _on_PlayerText_text_entered(new_text: String):
get_word()
func _on_Button_pressed():
if is_story_done():
reset_game()
else:
get_word()
func get_word():
add_player_word()
check_words_input()
func is_story_done():
return words.size() == prompts.size()
func add_player_word():
words.append(PlayerText.text)
DisplayText.text = ""
PlayerText.clear()
func tell_story():
DisplayText.text = story % words
func show_prompt():
DisplayText.text += "Please write a " + prompts[words.size()]
func check_words_input():
if (is_story_done()):
end_game()
else:
show_prompt()
func end_game():
PlayerText.queue_free()
tell_story()
func reset_game():
var tree_node: SceneTree = get_tree()
print(tree_node)
tree_node.reload_current_scene()