float sanityFactor = 10.0f;
float curSanity = 100.0f;
float oldSanity = 100.0f;
void OnStart()
{
SetPlayerSanity(100.0f);
AddTimer("SanityTimer", 0.5f, "UpdateSanity");
}
void UpdateSanity(string &in asTimer)
{
curSanity = GetPlayerSanity();
float temp;
if(curSanity < oldSanity)
{
temp = curSanity - sanityFactor;
SetPlayerSanity(temp);
}
if (curSanity > oldSanity)
{
temp = curSanity + sanityFactor;
if(temp <= 100.0f)
{
SetPlayerSanity(temp);
}
else
{
SetPlayerSanity(100.0f);
}
}
oldSanity = curSanity;
AddTimer("SanityTimer", 0.5f, "UpdateSanity");
}
I omitted any unrelated code (like lever turning lights on and off).
The draining works just fine when I turn the lights off, but as soon as I turn the lights, my sanity (no matter what) goes to "..."; basically, it doesn't gain sanity correctly. My code is insane somewhere.