#anyone know how i would get something like this to work

13 messages · Page 1 of 1 (latest)

tepid wren
#

Hello!

Button communication to Main script: Probably best to use a signal.
Can connect the pressed signal to a script on main scene through the editor. (Or through code if needed)

#

That will create a function named something like _on_button_pressed(),
inside of that function you can access scene_switching_handling and run a function on it

#

If this node doesn't change
You should be able to connect the button directly to scene_switching_handling

#

get_tree().current_scene could be helpful to get main scene

#

If you explain more about your tree structure and post a full screenshot (it seems like you're dynamically switching scenes through code?) I can give more specific advice

tepid wren
#

So when you select pressed signal to connect it, it gives you option of which script to add the function to
I was suggesting adding it to a new script attached to your main scene node, because it can easily access everything below it

#

ohh I see

#

your character selection ui is a scene itself

#

sorry I missed that

#

ok so you have a lot of options tbh

easiest to do right now would probably be something like this:

Disconnect the signal and get rid of the _on_exit_button_pressed() function

And then, in the _ready() function of character_selection_ui or main_scene...

# Get the button (change button_parent to the proper name of your exit button's parent)
var button = get_node("button_parent/exit_button")
# Get the "main scene" node
var main_node = get_tree().current_scene
# Connect the button pressed signal
button.pressed.connect(main_node.get_node("systems/scene_switching_handling").function_name)
#

If you put say_hi as the function_name it would connect the button to the say_hi() function inside scene_switching_handling node

#

You might be able to just get away with making character_selection_ui, not a scene of its own

#

so that you can connect it manually through editor like we tried before