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
switch and cases
Lizard Offline
Member

Posts: 174
Threads: 23
Joined: Jul 2012
Reputation: 5
#1
switch and cases

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

CURRENT PROJECT:
A Fathers Secret == Just started
(This post was last modified: 09-07-2013, 03:45 PM by Lizard.)
09-07-2013, 10:09 AM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#2
RE: switch and cases

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.
(This post was last modified: 09-07-2013, 02:46 PM by Apjjm.)
09-07-2013, 02:42 PM
Find
Lizard Offline
Member

Posts: 174
Threads: 23
Joined: Jul 2012
Reputation: 5
#3
RE: switch and cases

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

CURRENT PROJECT:
A Fathers Secret == Just started
(This post was last modified: 09-07-2013, 03:02 PM by Lizard.)
09-07-2013, 03:01 PM
Find
Kreekakon Offline
Pick a god and pray!

Posts: 3,063
Threads: 70
Joined: Mar 2012
Reputation: 124
#4
RE: switch and cases

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

Try putting this...
    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.

[Image: Tv0YgQb.gif]
Image by BandyGrass
(This post was last modified: 09-07-2013, 03:24 PM by Kreekakon.)
09-07-2013, 03:14 PM
Find
Lizard Offline
Member

Posts: 174
Threads: 23
Joined: Jul 2012
Reputation: 5
#5
RE: switch and cases

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

CURRENT PROJECT:
A Fathers Secret == Just started
09-07-2013, 03:31 PM
Find
Kreekakon Offline
Pick a god and pray!

Posts: 3,063
Threads: 70
Joined: Mar 2012
Reputation: 124
#6
RE: switch and cases

Put...

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.

[Image: Tv0YgQb.gif]
Image by BandyGrass
09-07-2013, 03:36 PM
Find
Lizard Offline
Member

Posts: 174
Threads: 23
Joined: Jul 2012
Reputation: 5
#7
RE: switch and cases

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

CURRENT PROJECT:
A Fathers Secret == Just started
09-07-2013, 03:44 PM
Find




Users browsing this thread: 2 Guest(s)