How do you call a function by opening a GUI?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Korbie

I am making a dashing mechanic in this test game, I already made the dash itself, but the problem is, I want to make it so you cant dash at the start but after opening a GUI, you can.
I dont have a clue on how I can do this. The dash itself is in a separate node, not in the player. My idea was to just set the dash var to false and then just make it true when the player opens the GUI, but I dont know how (im seriously new to godot) This is my dash Script:

extends Node2D

const dashDelay = 1

onready var durationTimer = $DurationTimer
onready var ghostTimer = $GhostTimer
var canDash = true
var ghostScene = preload(“res://DashGhost.tscn”)
var sprite

func start_dash(sprite, duration):
self.sprite = sprite
sprite.material.set_shader_param(“mix_weight”, 0.7)
sprite.material.set_shader_param(“colored”, true)

durationTimer.wait_time = duration


func instance_ghost():
var ghost: Sprite = ghostScene.instance()

ghost.global_position = global_position
ghost.texture = sprite.texture
ghost.vframes = sprite.vframes
ghost.hframes = sprite.hframes
ghost.frame = sprite.frame

func is_dashing():
return !durationTimer.is_stopped()

func end_dash():
sprite.material.set_shader_param(“colored”, false)
canDash = false
yield(get_tree().create_timer(dashDelay), “timeout”)
canDash = true

func _on_DurationTimer_timeout() → void:

func _on_GhostTimer_timeout() → void:

:bust_in_silhouette: Reply From: CollyBlargle

Try defining a signal in the GUI. Something like

In the GUI script, define the signal…

signal activate_dash(canDash)

and emit it when you open the GUI

emit_signal(“activate_dash”, true)

And emit it when you close the GUI

emit_signal(“activate_dash, false)

Then, in the player script, define the method.

    canDash = open

Then, in the scene that has both the GUI and the Player, connect the GUI to the Player.

playerPath = get_node(“Player”) #Your node path might be different. 
#You can find the node path of a node 
#by right clicking the node and clicking, 
#"Copy Node Path"
guiPath = get_node(“GUI”)
guiPath.connect(“activate_dash”, playerPath, “_on_activate_dash”)