0 votes

[SOLVED]
It was necessary to add the word "void" after the "delegate"

Hello,

I am doing a lesson that is written in GDScript, trying to translate the code into C#.
https://www.youtube.com/watch?v=NK_SYVO7lMA
time 15:38
But I am getting Build error

using Godot;
using System;

public class Player : Area2D
{
    float health = 10;

    [Signal] public delegate healthChanged(float newHealth);


    void TakeDamage(float amount)
    {
        health -= amount;
        if (health < 0)
            health = 0;

        GetNode<AnimationPlayer>("AnimationPlayer").Play("take_damage"); 

        EmitSignal("healthChanged", health);
    }

    private void _on_area_entered(Area2D area)
    {
        TakeDamage(2);
    }
}

Failed to build project solution
error CS1001: Identifier expected [/Volumes/Data/Godot/LEARN Signals/LEARN Signals.csproj]

And in Visual Studio this line is highlighted (underlined the word "healthChanged"):

public delegate healthChanged(float newHealth);

The type 'Player' already contains a definition for '' [Using signals, LEARN Signals]csharp(CS0102)
The type or namespace name 'healthChanged' could not be found (are you missing a using directive or an assembly reference?) [Using signals, LEARN Signals]csharp(CS0246)

Godot version 3.5.stable.mono.official[991bb6ac7]
in Engine by (23 points)

You may wanna add the solution as answer? :)

1 Answer

0 votes
Best answer

It was necessary to add the word "void" after the "delegate"

[Signal] public delegate void healthChanged(float newHealth);
by (23 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.