Hey there,
I'm learning Godot atm and I'm stuck on connecting a custom signal to my method.

I've got my Singleton Node that holds player stats. Once the health changes, it emits the signal with the value.

	[Export] public float max_health = 1;
	[Signal] public delegate void no_healthEventHandler();
	[Signal] public delegate void health_changedEventHandler(int health);

	public float current_health;

	public override void _Ready()
	{
		current_health = max_health;
		AddUserSignal("no_health");
		AddUserSignal("health_changed");
	}

	public void takeDamage(int dmg)
	{
		current_health -= dmg;
		EmitSignal("health_changed", current_health);
		if(current_health <= 0)
		{
			EmitSignal("no_health");
		}
	}

I want to use this signal to change the hears in the UI, but I cannot connect the signal to my method. I tried different combinations of x.Connect() but it gives out errors.

private Node playerStats;

	public int hearts
	{
		set{Set_Hearts(value);}
		get{return hearts;}
	}

	public int max_hearts {set; get;}

	public void Set_Hearts(int value)
	{
		if(value >= 0 & value <= max_hearts)
		{
			hearts = max_hearts;
		}
	}

	public override void _Ready()
	{
		playerStats = GetNode<Node>("/root/PlayerStats");

		max_hearts = (int)playerStats.Get("max_health");
		hearts = (int)playerStats.Get("current_health");

		playerStats.Connect("health_changed", Callable.From(Set_Hearts));
	}

I know the line works only with methods that do not take any arguments and I cannot seem to find code that works with arguments. Does anyone knows how to go about it?

    Or what the proper syntax is?

    Any help is greatly appreciated.

    Thanks!

    2 months later

    UndeadCat

    When you use the [Signal] attribute and a delegate which is called SomethingEventHandler (EventHandler is important). Then Godot C# generates Events in the background that are called Something (without the EventHandler). After that you can use the normal C# way of connecting events +=.

    Something like this should work (I am not at my Godot machine so i cannot test it):

    	[Export] public float max_health = 1;
    	[Signal] public delegate void no_healthEventHandler();
    	[Signal] public delegate void health_changedEventHandler(int health);
    
    	public float current_health;
    
    	public override void _Ready()
    	{
    		current_health = max_health;
    	}
    
    	public void takeDamage(int dmg)
    	{
    		current_health -= dmg;
    		EmitSignal(SignalName.health_changed, current_health);
    		if(current_health <= 0)
    		{
    			EmitSignal(SignalName.no_health);
    		}
    	}
    private Node playerStats;
    
    	public int hearts
    	{
    		set{Set_Hearts(value);}
    		get{return hearts;}
    	}
    
    	public int max_hearts {set; get;}
    
    	public void Set_Hearts(int value)
    	{
    		if(value >= 0 & value <= max_hearts)
    		{
    			hearts = max_hearts;
    		}
    	}
    
    	public override void _Ready()
    	{
    		playerStats = GetNode<Node>("/root/PlayerStats");
    
    		max_hearts = (int)playerStats.Get("max_health");
    		hearts = (int)playerStats.Get("current_health");
    
    		playerStats.health_changed += Set_Hearts
    	}