Reputation: 105
I'm trying to make a few simple classes for my program and I'm being stumped by the inconsistent accessibility on field types error for my Tile[,] class 'theGrid' object. I've had a look at a few of the other solutions and set everything to public as I can see but I'm still stuck as to what to do with this.
Could you tell me how to fix this?
public class Level
{
public Tile[,] theGrid;
public Tile[,] TheGrid
{
get { return theGrid; }
set { theGrid = value;}
}
public static Tile[,] BuildGrid(int sizeX, int sizeY)
{
Tile earth = new Tile("Earth", "Bare Earth. Easily traversable.", ' ', true);
//this.createTerrain();
for (int y = 0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
theGrid[x, y] = earth;
}
}
return theGrid;
}
And here's a shortened version of the tile class:
public class Tile
{
//all properties were set to public
public Tile()
{
mineable = false;
symbol = ' ';
traversable = true;
resources = new List<Resource>();
customRules = new List<Rule>();
name = "default tile";
description = "A blank tile";
area = "";
}
public Tile(string tName, string tDescription, char tSymbol, bool tTraversable)
{
resources = new List<Resource>();
customRules = new List<Rule>();
area = "";
symbol = tSymbol;
this.traversable = tTraversable;
this.name = tName;
this.description = tDescription;
mineable = false;
}
public void setArea(string area)
{
this.area = area;
}
}
I'd appreciate any help you could give me with this one.
Upvotes: 0
Views: 2930
Reputation: 273294
The exact error message indicates that the accessibility of Tile
is less than public.
But in you listing of Tile
it is public.
Possible causes
Resource
or Rule
is declared internal (ie without public
)Tile
class public class Tile
is incorrect. Upvotes: 1
Reputation: 6882
Static methods can only access static members.
You need to create new array of tiles
public static Tile[,] BuildGrid(int sizeX, int sizeY)
{
Tile[,] theGrid = new Tile[sizeX, sizeY];
.... the rest of the code is the same
}
Upvotes: 2