#what s the issue with this

1 messages · Page 1 of 1 (latest)

tepid lotus
#

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'`
worldly geyser
tepid lotus
#

in the constructor of gridsystem

#

pathfinding and levelgrid both call it to generate gridsystems

worldly geyser
#

GridObject gridObject = GetGridObject(gridPosition); this should be TGridObject gridObject = GetGridObject(gridPosition);

tepid lotus
#

but then I can't call this if(!gridObject.GetIsWater()) {

#

Cannot resolve symbol 'GetIsWater'

worldly geyser
#

do all of the different types that you will be using for TGridObject have a GetIsWater() function?

tepid lotus
#

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;
    }```
worldly geyser
#

or an Abstract class for them to derive from

tepid lotus
#

ahh ok right, cause i want pathfinding and levelgrid to know this arbitrary data about a grid pos (if its water, lava etc)

worldly geyser
#

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 GetIsWater as grid objects
  • Allow you to call GetIsWater on a TGridObject variable inside the GridSystem class
tepid lotus
#

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

worldly geyser