#what s the issue with this
1 messages · Page 1 of 1 (latest)
because this generates gridObjectArray = new TGridObject[width, height]; i cant use
{
return gridObjectArray[gridPosition.x, gridPosition.z];
}```
``` GridPosition gridPosition = new GridPosition(x, z);
GridObject gridObject = GetGridObject(gridPosition);```
`GridObject gridObject = GetGridObject(gridPosition);` this line says `Cannot convert initializer type 'TGridObject' to target type 'GridObject'`
Wait where are you writing that code?
in the constructor of gridsystem
pathfinding and levelgrid both call it to generate gridsystems
GridObject gridObject = GetGridObject(gridPosition); this should be TGridObject gridObject = GetGridObject(gridPosition);
but then I can't call this if(!gridObject.GetIsWater()) {
Cannot resolve symbol 'GetIsWater'
do all of the different types that you will be using for TGridObject have a GetIsWater() function?
I think so
{
private GridSystem<GridObject> _gridSystem;
private GridPosition _gridPosition;
private List<Unit> unitList;
public bool isWater;
public GridObject(GridSystem<GridObject> gridSystem, GridPosition gridPosition, bool isWater)
{
this._gridSystem = gridSystem;
this._gridPosition = gridPosition;
unitList = new List<Unit>();
this.isWater = isWater;
}
...
{
return isWater;
}```
ok what you need then is an interface for them to implement
or an Abstract class for them to derive from
ahh ok right, cause i want pathfinding and levelgrid to know this arbitrary data about a grid pos (if its water, lava etc)
for example:
public interface IGridObject {
bool GetIsWater();
}
public class GridObject : IGridObject```
```cs
public class PathNode : IGridObject```
and then the big whammy:
```cs
public class GridSystem<TGridObject> where TGridObject : IGridObject```
that will do a few things:
- make sure you can only use types that implement
GetIsWateras grid objects - Allow you to call
GetIsWateron aTGridObjectvariable inside theGridSystemclass
ahhh thank you, ok cool
i'll tinker away and see how I go
this concept is bit tough for me to learn, if I need to google stuff what terms should I google?
generics? interface? to learn the fundamentals/concept
your explanation makes a lot of sense though, i think I get it
- C# interfaces for the interface
- C# generic type constraints for the
whereclause