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
Help with "advanced widget script"
Ge15t Offline
Junior Member

Posts: 48
Threads: 8
Joined: Feb 2011
Reputation: 0
#1
Help with "advanced widget script"

void OnStart()
{
    AddEntityCollideCallback("Player", "StartFootsteps", "ScaryFootsteps", true, 1); //add to your OnStart()
}

void ScaryFootsteps(string &in asParent, string &in asChild, int alState)
{
    for(int s=1;s<11;s++) AddTimer("step"+s, 0.8 * s, "CreateFootstep");
}

void CreateFootstep(string &in asTimer)
{
    PlaySoundAtEntity("scary"+asTimer, "stepfile.snt", asTimer, 0, false);
    if(asTimer == "step2") {
        //Do some scary stuff
    }

Ok so this is the the script that I want to play with the foot step noises, but i cant seem to get it working. Can someone help me out here? the footsteps file is scare_wood_creak_mix.snt.

I just need some clearer instructions on what exactly the
(int s=1;s<11;s++) AddTimer("step"+s, 0.8 * s, "CreateFootstep");
code means and how to structure the script properly.
05-07-2011, 03:19 PM
Find Reply
Apjjm Offline
Is easy to say

Posts: 495
Threads: 18
Joined: Apr 2011
Reputation: 51
#2
RE: Help with "advanced widget script"

for(int s=1;s<11;s++) AddTimer("step"+s, 0.8 * s, "CreateFootstep");


The loop there takes the following form:
for ( <1> ; <2> ; <3>)  {<4> }

<1> : Done at the very start of the loop. Usually we declare a variable.
<2> : Boolean (True/False) value deciding if we should exit the loop or not yet.
<3> : Action performed at the end of each iteration of the loop.
<4> : The actual code that is performed each iteration. (note that if only 1 thing is done you don't need the {}'s).

In this case, we define an integer variable called "s" at the start of the loop. "s" is initialised to 1, and will increment by 1 (s++) whilst "s < 11". This means AddTimer(..) is called like so:

AddTimer("step"+1, 0.8 * 1, "CreateFootstep");
AddTimer("step"+2, 0.8 * 2, "CreateFootstep");
AddTimer("step"+3, 0.8 * 3, "CreateFootstep");
...
AddTimer("step"+9, 0.8 * 9, "CreateFootstep");
AddTimer("step"+10, 0.8 * 10, "CreateFootstep");
So what this is actually doing, is creating 10 timers called "step1" through "step10", each waiting 0.8 seconds longer than the previous one. When each of these timers expires the function called "CreateFootstep" is called.

"CreateFootstep" creates a footstep sound in the code shown. Though note that the callback also has an argument which is the timer that actually called the function. This gives you the option to do something on a given footstep. E.g for the 2nd footstep, you could check if "asTimer" was equal to "step2", and perform the actions you wish to perform.

(This post was last modified: 05-07-2011, 05:29 PM by Apjjm.)
05-07-2011, 05:26 PM
Find Reply
Ge15t Offline
Junior Member

Posts: 48
Threads: 8
Joined: Feb 2011
Reputation: 0
#3
RE: Help with "advanced widget script"

Ok so what about
void CreateFootstep(string &in asTimer)
{

    PlaySoundAtEntity([b]"scary"[/b]+asTimer, "scare_wood_creak_mix.snt", "StartFootstepsArea", 0, false);
    if(asTimer == "step2")
  
}

Ok so copy pasted straight from the adv script widgets page,
//make sure asTimer (the name of the timer which calls the CreateFootsteps function) MATCHES the area you want to play the step at. In this case, your areas MUST be named "step1", "step2", etc until you reach "step10", just as the timers are named "step1", "step2", etc. There are only 10 steps, because the for loop stops when s reaches 11.

So for this bit, would I have to create 10 'areas' named step1, step2 etc which the function would call each at 0.8 seconds? And for the bit i put in bold, what is that?? And do I need
if(asTimer == "step2")
?

This is honestly doing my head in lol. and steam isnt working atm so i cant test it out, but want to get it right.
05-08-2011, 06:41 AM
Find Reply
Apjjm Offline
Is easy to say

Posts: 495
Threads: 18
Joined: Apr 2011
Reputation: 51
#4
RE: Help with "advanced widget script"

if(asTimer == "step2")
This is just an example of how to check for a specific footstep - in this case the second one. You don't need this line, or can change it to a different footstep. Why? well you might want to lower player sanity or shut a door or something on a given step.

Quote:So for this bit, would I have to create 10 'areas' named step1, step2 etc which the function would call each at 0.8 seconds? And for the bit i put in bold, what is that??

that function is of the following form:
//From the script functions page in the wiki:
void PlaySoundAtEntity(string& asSoundName, string& asSoundFile, string& asEntity, float afFadeTime, bool abSaveSound);

//The code used
PlaySoundAtEntity("scary"+asTimer, "scare_wood_creak_mix.snt", "StartFootstepsArea", 0, false);
The first argument is just a name to give the sound you are playing - it is given the name "scarystepX" (where X is a number between 1 and 10) in this case - so each sound is uniquely named. The next argument is the sound you want to play.
asEntity, is the place to play the footstep at - and set to "StartFootstepsArea". This means you only need one script area called "StartFootstepsArea". The last two arguments state a fade-in time (of 0) and whether the state of the sound should be saved.

However, if you want to make it so you have 10 areas - one for each footstep, you can simply do the following:
PlaySoundAtEntity("scary"+asTimer, "scare_wood_creak_mix.snt", "Foot"+asTimer, 0, false);
"Foot"+asTimer will yeild "Footstep1" through "Footstep10" as the entity names.

05-08-2011, 02:32 PM
Find Reply




Users browsing this thread: 1 Guest(s)