0

Please help! I keep getting this error message when I run my code for a title page for my game! I'm quite new to Godot. Here's the scene tree:

Image

TitleScreen - Control Node

- ColorRect - ColorRect Node
- Menu - VBoxContainer Node
    - Label - Label Node
    - Buttons - VBoxContainer Node
        - PlayButton - Button Node
        - QuitButton - Button Node
- Fade - ColorRect

Here is the GDScript code connected to both the PlayButton and the QuitButton:

extends Button

export(String) var scene_to_load
export(bool) var quit

func _ready():
    for button in $Menu/Buttons.get_children():
        button.connect("pressed", self, "_on_button_pressed", [button.scene_to_load])

func _on_button_pressed():
    get_tree().change_scene(scene_to_load)

When I run said Scene I get:

get_node: Node not Found: Menu/Buttons

Any Help would be appreciated :)

Thank you for your help with solving my problem! My Title Screen After being fixed :)

My game Game

General Grievance
  • 4,555
  • 31
  • 31
  • 45

1 Answers1

1

You said you've connected the GDScript code to each Button, but it looks like you should have the script connected to the TitleScreen instead as $Menu is a child of TitleScreen and not Button.

You'll need to fix the script also to extend Control instead of extend Button as it is currently

Edit

Honestly though, if you just want to load a particular scene from a button press and nothing else you can simply change the scene directly from the button - this is just a script change

extends Button

export(String) var scene_to_load
export(bool) var quit

func _ready():   
    self.connect("pressed", self, "_on_button_pressed")

func _on_button_pressed():
    get_tree().change_scene(scene_to_load)
pm101
  • 1,309
  • 10
  • 30
  • How can I get the scene_to_load be for each of the buttons? I added a new script that just ads the variables for each button (Quit(bool) and scene_to_load) but now scene_to_load is not defined, but I want it to be specific for each button. –  Mar 31 '21 at 12:42
  • if you just want to load a particular scene from a button press and nothing else you can simply change the scene directly from the button (see edit) – pm101 Mar 31 '21 at 13:03
  • The identifier "button" isn't declared in the current scope... Again, I'm quite new to this sorry. –  Mar 31 '21 at 13:07
  • oops let me fix that - change `button` to `self` – pm101 Mar 31 '21 at 13:20
  • Thank you so much, thank you so, so, so much –  Mar 31 '21 at 13:22