NotImplementedException

Hello mister Monkey.
Everything worked fine until the sequence where we change the code to return tile coordonates rather than worldposition.
I was able to display the allowed tiles as you but when I’ve done the other part of the video, when I click with the mouse this error message appear:

It sends me to the line corresponding to this one :

I’ve check all the code many time but don’t understand what happen :grimacing:

Any idea?
Thanks so far.
Schuuss
François

Did you implement all the overloads in the GridPosition struct? Did you implement Equals(); GetHashCode(); etc?

Well, I don’t remember having change this script in this lesson.
I join you the actual code of my GridPosition Script.





using System;

public struct GridPosition : IEquatable<GridPosition>
{
    public int x;
    public int z;

    public GridPosition(int x, int z)
    {
        this.x = x;
        this.z = z;
    }

    public override bool Equals(object obj)
    {
        return obj is GridPosition position &&
               x == position.x &&
               z == position.z;
    }

    public bool Equals(GridPosition other)
    {
        throw new NotImplementedException();
    }

    public override int GetHashCode()
    {
        return HashCode.Combine(x, z);
    }

    public override string ToString()
    {
        return "x: " + x + " z: " + z;
    }

    public static bool operator ==(GridPosition a, GridPosition b)
    {
        return a.x == b.x && a.z == b.z;
    }

    public static bool operator !=(GridPosition a, GridPosition b)
    {
        return !(a ==b);
    }

    public static GridPosition operator +(GridPosition a, GridPosition b)//Création de la méthode pour autoriser les additions de grid position dans le script MoveAction ligne 65.
    {
        return new GridPosition(a.x + b.x, a.z + b.z);
    }

    public static GridPosition operator -(GridPosition a, GridPosition b)//Création de la méthode pour autoriser les soustarctions de grid position dans le script MoveAction ligne 65.
    {
        return new GridPosition(a.x - b.x, a.z - b.z);
    }

}


This is your problem. We made this changed a few videos earlier (Grid System & Camera - Level Grid at around 12:00)

This function should be

public bool Equals(GridPosition other)
{
    return this == other;
}
1 Like

Hello Bixarrio.
You’re right, it was that.
Thanks for the fixing :wink:
Everything work perfectly.
Have a nice day
François

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms