Frictional Games Forum (read-only)
switch and cases - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: switch and cases (/thread-22753.html)



switch and cases - Lizard - 09-07-2013

Hi guys.

It's first time i play with switch and cases, so i was prepared on running into trouble, but now im hitting the spot where im kind of stuck.

I just cant get this to work.


void OnStart
{
AddEntityCollideCallback("Player", "EventArea", "RandomEvent", true, 1);
AddTimer("event", 1, "EventTimer");
}

void RandomEvent(string &in asParent, string &in asChild, int alState)
{
switch(GetLocalVarInt("Var1"))
{
case 1:
StartScreenShake(0.06, 5, 1, 2);
PlaySoundAtEntity("laugh", "00_laugh.snt", "shield02_5", 0, false);
GiveSanityDamage(10, true);
break;
case 2:
StartScreenShake(0.06, 5, 1, 2);
PlaySoundAtEntity("laugh", "00_laugh.snt", "shield02_5", 0, false);
GiveSanityDamage(100, true);
break;
case 3:
PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false);
FadeSepiaColorTo(0.3, 2);
FadeRadialBlurTo(0.3, 2);
StartScreenShake(0.1, 11, 0, 1);
GiveSanityDamage(25, true);
AddTimer("NoramlScreen", 10, "NormalScreen");
AddTimer("PlayerReact", 1.5, "PlayerReact");
break;
case 4:
PlaySoundAtEntity("", "insanity_monster_roar02.ogg", "Player", 0, false);
FadeSepiaColorTo(0.3, 2);
FadeRadialBlurTo(0.3, 2);
StartScreenShake(0.1, 6, 0, 1);
GiveSanityDamage(100, true);
AddTimer("NoramlScreen", 5, "NormalScreen");
AddTimer("PlayerReact", 1.5, "PlayerReact");
break;
case 5:
AddEffectVoice("CH02L17_Alexander_01.ogg", "", "", "CH02L17_Alexander_01.ogg", false, "", 0, 0);
break;
}
if(GetLocalVarInt("Var1") == 6)
{
SetLocalVarInt("Var1", 0);
}
}

void PlayerReact(string &in asTimer)
{
PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);
}

void NormalScreen(string &in asTimer)
{
FadeRadialBlurTo(0, 2);
FadeIn(2);
}

void EventTImer(string &in asTimer)
{
AddLocalVarInt("Var1", 1);
AddTimer("event", 1, "EventTimer");
}


RE: switch and cases - Apjjm - 09-07-2013

Could you explain a little more what you are exactly trying to achieve and how the current script fails to do this? I do spot one potential flaw at first glance as well as an issue with the timer callback name (EventTImer has I in caps) but without knowing the intended behavior of the script i cannot really say if this is the bug or not: After 6 steps of "EventTimer" none of the random event cases will fire, and when "Var1" reaches 7 or over in the timer it is never reset to 0.


RE: switch and cases - Lizard - 09-07-2013

The timer flaw i've already dealt with (EventTImer to EventTimer), but it still wont work...

The idea with the timer is, that "var1" should raise to 6 and then go back to 0 and raise again.

But when i enter the area that should start RandomEvent nothing happens


RE: switch and cases - Kreekakon - 09-07-2013

I haven't scoured the entire script yet for problems, but I believe this may be one of them:

Try putting this...
Code:
    if(GetLocalVarInt("Var1") == 6)
    {
    SetLocalVarInt("Var1", 0);
    }

...under the timer's script instead of the EntityCollide. What's happening right now is that the timer is likely keeps activating over, and over again, which in turn keeps making your "Var1" larger, and larger well past 6. So when you do collide with your script area it will not be reset to 0, because "Var1" has likely long past since passed 6, and therefore no longer equals the conditions of "GetLocalVarInt("Var1") == 6"

EDIT: Oh yeah, basically the same thing Apjjm pointed out. It will result in none of the randoms ever happening unless you run to the script area in under 6 seconds.

EDIT 2: In a nutshell...your current resetting var1 to 0 script will not work unless you hit the script area at exactly six seconds.


RE: switch and cases - Lizard - 09-07-2013

I've tryed to work forth and back with it for sometime, but i cant find a way to fix this.
This is what i have now

void OnStart()
{

AddEntityCollideCallback("Player", "EventArea", "RandomEvent", true, 1);

AddTimer("event",1 , "EventTimer");

if(GetLocalVarInt("Var1") == 6)
{
SetLocalVarInt("Var1", 0);
}
}


void RandomEvent(string &in asParent, string &in asChild, int alState)
{
switch(GetLocalVarInt("Var1"))
{
case 1:
StartScreenShake(0.06, 5, 1, 2);
PlaySoundAtEntity("laugh", "00_laugh.snt", "shield02_5", 0, false);
GiveSanityDamage(10, true);
break;
case 2:
StartScreenShake(0.06, 5, 1, 2);
PlaySoundAtEntity("laugh", "00_laugh.snt", "shield02_5", 0, false);
GiveSanityDamage(25, true);
break;
case 3:
PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false);
FadeSepiaColorTo(0.3, 2);
FadeRadialBlurTo(0.3, 2);
StartScreenShake(0.1, 11, 0, 1);
GiveSanityDamage(50, true);
AddTimer("NoramlScreen", 10, "NormalScreen");
AddTimer("PlayerReact", 1.5, "PlayerReact");
break;
case 4:
PlaySoundAtEntity("", "insanity_monster_roar02.ogg", "Player", 0, false);
FadeSepiaColorTo(0.3, 2);
FadeRadialBlurTo(0.3, 2);
StartScreenShake(0.1, 6, 0, 1);
GiveSanityDamage(100, true);
AddTimer("NoramlScreen", 5, "NormalScreen");
AddTimer("PlayerReact", 1.5, "PlayerReact");
break;
case 5:
AddEffectVoice("CH02L17_Alexander_01.ogg", "", "", "CH02L17_Alexander_01.ogg", false, "", 0, 0);
break;
}
}

void PlayerReact(string &in asTimer)
{
PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);
}

void NormalScreen(string &in asTimer)
{
FadeRadialBlurTo(0, 2);
FadeIn(2);
}

void EventTimer(string &in asTimer)
{
AddLocalVarInt("Var1", 1);
AddTimer("event", 1, "EventTimer");
}


RE: switch and cases - Kreekakon - 09-07-2013

Put...

Code:
if(GetLocalVarInt("Var1") == 6)

    {

SetLocalVarInt("Var1", 0);

    }

...at the very bottom of the function EventTimer.

Right now you relocated it to OnStart which means it will only try to check at the very beginning which is completely pointless.


RE: switch and cases - Lizard - 09-07-2013

Damn i still got alot to learn. But thanks, it works now