I'm in the progress of exposing Npc ai routines to AngelScript.
Every npc is created/destroyed by the game engine and has its own ai context.
i want to do something like this (AngelScript code)
float lastSeenPlayer = 0;
void BasicMeleeAggressive(Npc @npc)
{
PatrolLeftAndRight(npc);
lastSeenPlayer += TimeSinceLastFrame();
if(npc.IsPlayerInLOS(10))
{
lastSeenPlayer = 0;
}
if(lastSeenPlayer < 5)
{
npc.GoTo(pc.GetXPosition(), pc.GetYPosition());
}
}
problem is, more than one npc object call this script. I have read in manual that lastSeenPlayer is global between contexts.
ofcourse i can add something like this to npc object
unordered_map<string, float> scriptFloats;
float GetFloat(const string &varname)
{
...
}
void SetFloat(const string &varname, float value)
{
...
}
passing a string is not really ideal for performance.
Is there a way to let each context own their global variables?
Thank you