However, all this information we give is useless, as long as you do not get the really important things right.
I think you treat programming as an exercise to make a computer do something you want.
But that's only half of it.
You do not only write code so it works for the computer - you MAINLY write code for yourself, so YOU (or others) can work with it. So it can be further developed. ← That's the most important aspect, which you seemingly missed your whole life long.
Which means your teachers sucked at their job, or they really tried, gave up, but did let you slip still for whatever reason.
You must change this. You may think you are too old to do changes. But there is no other way. The alternative is to keep wasting time with no outcome. You decide.
Ok, now let's make an example of what situation we we would have if you had taken my advice of yesterday serious:
class HexGrid
{
int *cellData; // can be std::vector, or two dimensional array... whatever
int width, weight;
float originInWorldspace[2]; // ... and whatever we need to define our map space
// We add our conversation functions here:
void WorldSpaceToHexGrid (int hexGrid[2], const float worldSpaceCoords[2]);
void HexGridToWorldSpace (float worldSpaceCoords[2], const int hexGrid[2]);
};
TankGame::ProcessUserInput (HexGrid &myHexMap, Tank &playerTank)
{
float cursorInWorldSpace[2];
ConvertMouseCoordsToWorldSpace(cursorInWorldSpace, mouseX, mouseY); // yes - we made such cool tool function as well somewhere, eventually
int hooveredHexGrid[2];
myHexMap WorldSpaceToHexGrid (hooveredHexGrid, cursorInWorldSpace);
// i call this usefull function also from game logic update, physics update, rendering, and dozens of other stuff :)
// Thus i never need to think about annoying mapping of world space to grid space again! :D
if (mouseButtonClicked)
{
playerTank.SetGoal (hooveredHexGrid);
}
}
Notice: Once i have those nasty conversation helper functions, problem solved, and i use them to move tanks, map mouse pos to grid, and anything else.
But you do not. You may think: ‘I'll do those functions eventually later. Right now, all i want is to find the hex tile where the mouse pointer is.’
I can understand this, and sometimes i do the same thing, even i know i should not.
But seemingly you ALWAYS go this ‘one problem after another' route, so you have no real progress, and you do not build up a code base which provides you with tools and solutions of frequent problems.
You solve the same problems again and again with slight variations, even if it leads to terribly inefficient solutions as you have just shown.
And something stupid like a compiler error becomes your new ‘actual problem’, so let's make a new post and ask for help.
Then you fix the error, and it finally works, so it is done and fine.
But it is not fine, because you have achieved nothing to help you with the work still ahead of you!
Code for yourself, not for the calculator machine in front of you.