C
C#14mo ago
JRL

classes

when i call GetPiece() function it returns null everytime and im not sure why
6 Replies
JRL
JRLOP14mo ago
Jimmacle
Jimmacle14mo ago
1: don't write get and set methods, C# has properties for this purpose 2: your ResetBoard code has a path that passes null as a piece as for "every time," that's not true so you'll have to be more specific about what code isn't working and what exceptions you're getting as an example of properties, your Spot class should be
public class Spot
{
public Piece Piece { get; set; }
public int X { get; set; }
public int Y { get; set; }

public Spot(int x, int y, int piece)
{
X = x;
Y = y;
Piece = piece;
}
}
public class Spot
{
public Piece Piece { get; set; }
public int X { get; set; }
public int Y { get; set; }

public Spot(int x, int y, int piece)
{
X = x;
Y = y;
Piece = piece;
}
}
JRL
JRLOP14mo ago
hi thanks i wasnt i aware im new to c# "2: your ResetBoard code has a path that passes null as a piece" what do u mean by this?
Jimmacle
Jimmacle14mo ago
i mean you have a line: boxes[i, j] = new Spot(i, j, null); that is the only place i see null being set as the piece
JRL
JRLOP14mo ago
even without that if i just have boxes[0, 0] = new Spot(0, 0, new Horse());
Debug.Log(boxes[0, 0].Piece); it still returns null when i try to access the piece nvm im just been stupid it does work thanks for ur help
Jimmacle
Jimmacle14mo ago
pepeok
Want results from more Discord servers?
Add your server