- Edited
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?