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
Make things play in a specific order?
Neatherblade Offline
Junior Member

Posts: 19
Threads: 5
Joined: Jan 2011
Reputation: 0
#1
Make things play in a specific order?

I want this to play

void OnStart()
{
AddEntityCollideCallback("Player", "scary_trigger", "ScaryTriggerFunc", true, 1);
}

void ScaryTriggerFunc(string &in asParent, string &in asChild, int alState)
{

StartPlayerLookAt("look_blood", 4, 2, "");
AddTimer("", 2.5f, "ScaryMoment");
PlayGuiSound("react_scare.snt", 100); <------------ play this first
GiveSanityDamage(25, true);


StartPlayerLookAt("look_stair", 4, 2, "");
PlayGuiSound("react_breath_slow.snt", 100); <------------ play this seconde
PlayGuiSound("notice.snt", 40);
StartScreenShake(0.1f, 2, 0.2f, 1);


StartPlayerLookAt("look_monster", 4, 2, "");
AddTimer("", 2.5f, "ScaryMoment");
PlayGuiSound("react_pant.snt", 100); <------------ play this last
GiveSanityDamage(15, true);

}

At the moment it jumps to the last one
01-09-2011, 04:53 PM
Find
Andross Offline
Junior Member

Posts: 38
Threads: 1
Joined: Oct 2010
Reputation: 0
#2
RE: Make things play in a specific order?

If I'm not mistaken, you seem to be under the misconception that AddTimer() waits for the given amount of time. Instead, it calls the given function (in your case it would be "ScaryMoment") after the specified time interval, but the flow of execution will not be halted in the meantime.
Thus, what you need is either a cascade of functions that each add a timer to the respective next one or one function that adds a timer to call itself and decide based on a state variable which action to take on each iteration.

The following should work; I haven't tested it, though.

Spoiler below!

Sorry for the lack of indentation:

void OnStart()
{
AddEntityCollideCallback("Player", "scary_trigger", "ScaryTriggerFunc", true, 1);
}

void ScaryTriggerFunc(string &in asParent, string &in asChild, int alState)
{
AddLocalVarInt("ScaryState", 0);
AddTimer("ScaryTimer", 0.0f, "ScaryTimerFunc");
}

void ScaryTimerFunc(string &in timer_name)
{
int state = GetLocalVarInt("ScaryState");

switch(state) {
case 0:
StartPlayerLookAt("look_blood", 4, 2, "");
PlayGuiSound("react_scare.snt", 100);
GiveSanityDamage(25, true);
break;
case 1:
StartPlayerLookAt("look_stair", 4, 2, "");
PlayGuiSound("react_breath_slow.snt", 100);
PlayGuiSound("notice.snt", 40);
StartScreenShake(0.1f, 2, 0.2f, 1);
break;
case 2:
StartPlayerLookAt("look_monster", 4, 2, "");
PlayGuiSound("react_pant.snt", 100);
GiveSanityDamage(15, true);
break;
default:
return;
}

SetLocalVarInt("ScaryState", state + 1);
AddTimer(timer_name, 2.5f, "ScaryTimerFunc");
}


Also note that all of the script functions of the HPL2 are non-blocking.
(This post was last modified: 01-09-2011, 05:49 PM by Andross.)
01-09-2011, 05:10 PM
Find
Neatherblade Offline
Junior Member

Posts: 19
Threads: 5
Joined: Jan 2011
Reputation: 0
#3
RE: Make things play in a specific order?

Could not get that code to work, but i fixed it with triggers instead.
Thanks anyway.
01-09-2011, 06:37 PM
Find




Users browsing this thread: 1 Guest(s)