Could we maybe rewrite the ZScript compiler to perform an additional type check whenever it references a global pointer?


Similar to option #2, we could have:
int npc_id = Game->SaveNPC(enemy);
// ...
npc n = Game->LoadNPC(npc_id);
That would let you implement it however you wanted under the hood, instead of being forced to use an array. Since we're not using uuids directly, there's no danger of getting the wrong type. Whenever an object expires, you can have it check to see if it's saved globally, and delete that entry? Or you could, as above, stick the type check into the Game->Load calls.


For reference, my current "standard" workaround is to store an "id" in the misc array for each object. The NPC_ScreenIndex(id) and similar functions build an object_id -> screen_index mapping the first time they're called in a given frame.