Turn-based Strategy Course - Generics

I’m not the best coder, so don’t know why, but had to use <TGridObject> instead of <GridObject> to get the LevelGrid.cs and GridObject.cs scripts to work.

Had to abandon Generics… can’t/don’t know how to fix GridSystem.cs error in CreateDebugObjects()… as TGridObject/ as GridObject doesn’t work.

TGridObject is the name for the generic type, so you use that type in the GridSystem where you’re defining the generic.
However when you’re using it and instantiating a new GridSystem like in LevelGrid you should be referencing the actual class you want to use so yes in LevelGrid you create a GridSystem with GridObject.

What error do you have?

Hi,

I get: ‘The type or namespace ‘GridObject’ could not be found…’

Anyhow, it’s Saturday, and you shouldn’t be working… boa noite :slight_smile:

Maybe you added the generic definition to the GridObject instead of the GridSystem? If you change GridObject definition to GridObject then the type GridObject no longer exists because it only exists with generics.
Either that or you accidentally deleted the GridObject file.
You can check the GitLab commit for every lecture and compare with your own code to see where you might have written something wrong
Heh don’t worry I always answer questions on weekends

2 Likes

I see this question is still open so just a thought if it’s still unresolved. I accidentally changed more references from ‘GridObject’ to ‘TGridObject’ than I intended with a find and replace across multiple documents instead of just in the GridSystem class. So when I got to this line I was getting an error even as I added ‘as GridObject’. The issue for me was in the GridDebugObject class which had an erroneous reference to TGridObject so changing that back to GridObject fixed the issue for me.

Good luck finding the incorrect reference.

1 Like

Hi, meant to update this question but forgot to. I used VSCode to rename GridObject to TGridObject and it renamed it globally. Once the code was corrected, the grid system worked fine. I eventually got past this hurdle, but abandoned the course because it was clear that I was simply being a copytypist ‘Monkey see, Monkey do’, without gaining any core understanding of what the code was going or why. One day, when I have a better understanding of C#, I may return to it, but, for now, beginner coding is more my level – intermediate is just too advanced, or rather the course’s intermediate coding is too advanced.

1 Like

Hi Mo-Moxi. You’re quite right, there are plenty of intermediate concepts in this course that can trip up beginning students. We try our best to keep the code accessible, but at the same time we still need to present the more intermediate and advanced concepts.

Take heart, we were all beginning coders at one point or another, even our instructors.

I’d encourage you to return to the course work soon. It may take a couple passes through the course, but as you work with the code repeatedly, you’ll soon find you get a greater understanding of the concepts.

7 Likes

Privacy & Terms