Text Scene Switching

Godot Version

4.6.2 Stable

How do I switch scenes when specific text is written?

I’m trying to have my scene switch from my custom, in app terminal, to my custom desktop when the user types “boot os”, but instead of having to type out the entire thing, I type a single character and it switches to the desktop. If anyone has any solutions, help would be great! Thank you a lot!

If you share code, please wrap it inside three backticks or replace the code in the next block:

extends CodeEdit

#forces the user to type in the app's terminal.
func _ready():
    grab_focus()

#changes the scene from the terminal to the desktop when "boot os" is typed.
func _on_text_changed() -> void:
    text = "boot os"
    get_tree().change_scene_to_file("res://desktop.tscn")

You have no logic check before switching the scene. This should work:

func _on_text_changed() -> void:
    if text == "boot os":
        get_tree().change_scene_to_file("res://desktop.tscn")
2 Likes

Thank you so much for the help! I owe you one!