C
C#18h ago
cowbloke

✅ inaccessible due to its protection level error when the const i'm reaching is public

using Godot;
using System;
using ChessEngine;
using System.Collections.Generic;

public partial class GodotBridge : Node
{
ChessBoard board = new ChessBoard(); // Create the main instance of the ChessBoard
MoveGenerator MoveGenerator = new MoveGenerator(); // Create a movegenerator
FenParser fenParser = new FenParser(); // Create an instance of FenParser

public override void _Ready()
{
PrecomputedMoveData.PrecomputeMoveData();
board = fenParser.ParseFen(FenParser.startingFen); // Use the type name to call startingFen <-- error here

Console.WriteLine(MoveGenerator.GenerateMoves(board));
}

// Called every frame. 'delta' is the elapsed time since the previous frame.
public List<Move> GetMoves()
{

return MoveGenerator.GenerateMoves(board);
}
}
using Godot;
using System;
using ChessEngine;
using System.Collections.Generic;

public partial class GodotBridge : Node
{
ChessBoard board = new ChessBoard(); // Create the main instance of the ChessBoard
MoveGenerator MoveGenerator = new MoveGenerator(); // Create a movegenerator
FenParser fenParser = new FenParser(); // Create an instance of FenParser

public override void _Ready()
{
PrecomputedMoveData.PrecomputeMoveData();
board = fenParser.ParseFen(FenParser.startingFen); // Use the type name to call startingFen <-- error here

Console.WriteLine(MoveGenerator.GenerateMoves(board));
}

// Called every frame. 'delta' is the elapsed time since the previous frame.
public List<Move> GetMoves()
{

return MoveGenerator.GenerateMoves(board);
}
}
fenparser.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChessEngine
{
public class FenParser
{

public const string startingFen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChessEngine
{
public class FenParser
{

public const string startingFen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
23 Replies
Pobiega
Pobiega18h ago
Can you show FenParser.ParseFen?
cowbloke
cowblokeOP18h ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChessEngine
{
public class FenParser
{

public const string startingFen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";

readonly Dictionary<string, int> pieces = new Dictionary<string, int>
{
{ "p", 1 },
{ "n", 2 },
{ "b", 3 },
{ "r", 4 },
{ "q", 5 },
{ "k", 6 },
{ "P", 9 },
{ "N", 10 },
{ "B", 11 },
{ "R", 12 },
{ "Q", 13 },
{ "K", 14 }
};

public ChessBoard ParseFen(string FenString)
{
ChessBoard board = new ChessBoard();
string[] parts = FenString.Split(' ');

// Parse the pieces
int i = 0;
string boardfen = parts[0];

Dictionary<string, int> scores = new Dictionary<string, int> { { "p", 0b0001 } };

while (i < boardfen.Length)
{
if (char.IsDigit(boardfen[i]))
{
i += (int)char.GetNumericValue(boardfen[i]);
}
else if (boardfen[i] == '/')
{
i++;
}
else
{
board.Board[i] = pieces[boardfen[i].ToString()];
}
}

return board;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChessEngine
{
public class FenParser
{

public const string startingFen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";

readonly Dictionary<string, int> pieces = new Dictionary<string, int>
{
{ "p", 1 },
{ "n", 2 },
{ "b", 3 },
{ "r", 4 },
{ "q", 5 },
{ "k", 6 },
{ "P", 9 },
{ "N", 10 },
{ "B", 11 },
{ "R", 12 },
{ "Q", 13 },
{ "K", 14 }
};

public ChessBoard ParseFen(string FenString)
{
ChessBoard board = new ChessBoard();
string[] parts = FenString.Split(' ');

// Parse the pieces
int i = 0;
string boardfen = parts[0];

Dictionary<string, int> scores = new Dictionary<string, int> { { "p", 0b0001 } };

while (i < boardfen.Length)
{
if (char.IsDigit(boardfen[i]))
{
i += (int)char.GetNumericValue(boardfen[i]);
}
else if (boardfen[i] == '/')
{
i++;
}
else
{
board.Board[i] = pieces[boardfen[i].ToString()];
}
}

return board;
}
}
}
there you go
Evyr
Evyr18h ago
you're calling startingFen on the FenParser type, not the instance fenParser
Pobiega
Pobiega18h ago
which is correct. public const startingFen means it belongs to the class, not an instance of the class
cowbloke
cowblokeOP18h ago
any solutions i find online about this error is adding the public keyword
Evyr
Evyr18h ago
oh, nevermind then
Pobiega
Pobiega18h ago
Honestly, cant see any errors related to access level here. Copied your code into a .net 9 console app and it compiles
cowbloke
cowblokeOP18h ago
i am using godot here
Pobiega
Pobiega18h ago
I don't know enough about godot to know how its build system works
cowbloke
cowblokeOP18h ago
No description
cowbloke
cowblokeOP18h ago
i'll ask on their server instead
Pobiega
Pobiega18h ago
can you try restarting godot and/or resetting the build cache?
cowbloke
cowblokeOP18h ago
they have a pretty deserted c# channel which is why i came here
Pobiega
Pobiega18h ago
thats what we normally do when the IDE insists on ghost errors
cowbloke
cowblokeOP18h ago
i'll give it a go reloading godot doesn't do anything
Pobiega
Pobiega18h ago
only thing I can suggest, you obviously shouldnt have any protection errors for a public const on a public class
cowbloke
cowblokeOP18h ago
how do i reload the cache on vs?
Pobiega
Pobiega18h ago
$vsdrunk
MODiX
MODiX18h ago
* close VS * remove the hidden folder .vs * remove all bin and obj folder next to each csproj (DO NOT TOUCH THE .git FOLDER OR WHAT'S INSIDE) * restart vs
cowbloke
cowblokeOP18h ago
my thoughts exactly heyy it worked
Pobiega
Pobiega18h ago
woo
cowbloke
cowblokeOP18h ago
cheers do i close the channel or something?
Pobiega
Pobiega18h ago
type /close

Did you find this page helpful?