Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Sanity to drain in the dark and increase in the light?
FragdaddyXXL Offline
Member

Posts: 136
Threads: 20
Joined: Apr 2012
Reputation: 7
#10
RE: Get Sanity to drain in the dark and increase in the light?

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.

Dark Seclusion Here
04-13-2012, 01:28 AM
Find


Messages In This Thread
RE: Get Sanity to drain in the dark and increase in the light? - by FragdaddyXXL - 04-13-2012, 01:28 AM



Users browsing this thread: 3 Guest(s)