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?
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#11
RE: Get Sanity to drain in the dark and increase in the light?

Here's how I would have done it Tongue
Spoiler below!

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);
}
}

curSanity = GetPlayerSanity();
oldSanity = curSanity;
AddTimer("SanityTimer", 0.5f, "UpdateSanity");
}


I bolded the thing you missed. You had to recalculate the current sanity after modifying it with the sanityFactor.
Also, I changed a '>' to a '>=' because sanity doesn't recover in light. You are in light when sanity is equal to it's previous value Smile

Hope this helps.

Edit: Bold doesn't work in code format :/

Also, I'd lower the sanity factor by quite a lot, losing 20 sanity per second seems a bit too much, maybe make it = 0.5-1

(This post was last modified: 04-13-2012, 02:12 AM by DRedshot.)
04-13-2012, 02:06 AM
Find
FragdaddyXXL Offline
Member

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

(04-13-2012, 02:06 AM)DRedshot Wrote: I bolded the thing you missed. You had to recalculate the current sanity after modifying it with the sanityFactor.
Also, I changed a '>' to a '>=' because sanity doesn't recover in light. You are in light when sanity is equal to it's previous value Smile

Hope this helps.

Edit: Bold doesn't work in code format :/

Also, I'd lower the sanity factor by quite a lot, losing 20 sanity per second seems a bit too much, maybe make it = 0.5-1
Yeah, I was staring at my code for a while and noticed the <=. And I was making it lose a lot to speed up the effect for testing. But would you look at that? It works now! (with the addition of that extra

curSanity = GetPlayerSanity();) I thought that because I hadn't changed curSanity in the Update method, I wouldn't need that.



Dark Seclusion Here
04-13-2012, 02:45 AM
Find




Users browsing this thread: 1 Guest(s)