Here's the localMap class I created, it's very basic right now:
localMap.h
1 2 3 4 5 6 7 8 9
#pragma once
#include "NPC.h"
class localMap
{
public:
float temperature;
localMap();
};
localMap.cpp
1 2 3 4 5 6
#include "localMap.h"
localMap::localMap()
{
temperature = 20.0f;
}
I create the localMap object in another script that gets passed into the NPC script using assignRegion...I'm also wondering if I did that code correctly? here it is:
assignRegion (part of NPC.cpp)
1 2 3 4
void NPC::assignRegion(localMap & _region)
{
region = &_region;
}
You have recursive #includes.
npc.h includes localmap.h
localmap.h includes npc.h
Why does localmap.h include npc.h? It doesn't use it.
Remove that include.
If you truly need class A to reference class B and class B to reference class A, you must use pointers and a forward declaration for one of the classes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// A.h
class B; // Forward declaration
class A
{
B* m_pb; // member pointer to B
// okay because it's a pointer
};
// B.h
#include "a.h" // okay if one file includes the other
// but not both including each other
class B
{
A* m_pa; // member pointer to A
};
wow. Thanks for the help--I took the #include "NPC.h" from the localMap.h file and it got rid of the errors--I can't remember why I was including that in the first place tbh. I think my intention was probably to do the reverse:
Basically, I'm having the NPC point to a region that it is associated with (that it resides in) and any functions I need to do to adjust the region can be handled there, but I think at one point I was planning to do the reverse and have the region hold onto the NPCs that reside in it. --I may have left that in there thinking that I would want to do both, in which case your example is really helpful if I need to do both.