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
Sequencing Events and Timers
rybray Offline
Junior Member

Posts: 31
Threads: 9
Joined: Aug 2011
Reputation: 1
#1
Sequencing Events and Timers

Trying to teach myself how to use timers. The tutorial from the wiki helped me with the set up, but I am getting errors on lines [11], [14], [15], [17], and [23]. I tried explaining what the lines did in my own terms with the // but they may be incorrect. There were two other questions I had:

-I have seen partSpeed and fEventSpeed used in regard to how long a part of a sequence will be, which is correct?
-How do you determine what goes in OnStart, and OnEnter, they seem very much the same to me. Thank you for your help.

void OnStart()
{
SetLocalVarInt("iIntro", 0); // sets timer sequence value to zero
}

void OnEnter()
{
AddTimer("IntroTimer", 1, "Intro"); //creates timer that begins in __ seconds
}

[11] void Intro(string &in asTimer)
{
AddLocalVarInt("iIntro", 1); //changes timer value from 0 to 1
[14] float fEventSpeed = 1f; //sets default time for parts: 1 second
[15] switch (GetLocalVarInt("iIntro")); //looks for value of timer
{
[17] case 1: //what it does if the value for iIntro is 1
fEventSpeed = 2f;
FadeIn(5);
PlaySoundAtEntity("", "scare_male_terrified.snt", "player", 3, false);
break;

[23] case 2: //if iIntro value is 2
fEventSpeed = .1f;
CreateParticleSystemAtEntity("", "ps_rose_petals_swirl.ps", "player", false);
break;
}

if (GetLocalVarInt("iIntro") <2) //if iIntro value is less than two,
{
AddTimer("IntroTimer", fEventSpeed, "Intro");
}
}

void OnLeave()
{

}
08-12-2011, 05:47 AM
Find
Juby Away
Senior Member

Posts: 290
Threads: 2
Joined: May 2011
Reputation: 5
#2
RE: Sequencing Events and Timers

(08-12-2011, 05:47 AM)rybray Wrote: Trying to teach myself how to use timers. The tutorial from the wiki helped me with the set up, but I am getting errors on lines [11], [14], [15], [17], and [23]. I tried explaining what the lines did in my own terms with the // but they may be incorrect. There were two other questions I had:

-I have seen partSpeed and fEventSpeed used in regard to how long a part of a sequence will be, which is correct?
-How do you determine what goes in OnStart, and OnEnter, they seem very much the same to me. Thank you for your help.

- Yes, but it only works if you write "fEventSpeed" or whatever you decide to call your variable into the timer command. AddTimer("IntroTimer", fEventSpeed, "Intro"); will take whatever "fEventSpeed" equals and use that for the "wait" time.

- OnStart should be used for callbacks, if in OnEnter, they will be called every time the map is entered, which is not what most people want. OnStart should be for the stuff you want to only happen once, while OnEnter should be for the stuff you want to happen more than one time.





Insanity. Static.
08-12-2011, 12:25 PM
Find
Khyrpa Offline
Senior Member

Posts: 638
Threads: 10
Joined: Apr 2011
Reputation: 24
#3
RE: Sequencing Events and Timers

Everything you put inside OnEnter() happen when the map starts everytime,
everything you put inside OnStart() happen the first time you enter the map.

Then about the event you made:
if you use float values (numbers with f behind) you must use decimals ie. 0.5f 1.0f.
You don't need to set the iIntro variable into 0 at start because AddLocalVarInt atomatically sets it from 0 to 1.
To use FadeIn, you have to first use FadeOut.
You can use any name instead of fEventSpeed.

Heres the script (I added preloads cos everyone forgets to add them):

void OnStart()
{FadeOut(0);
AddTimer("IntroTimer", 1, "Intro");
}

void Intro(string &in asTimer)
{
AddLocalVarInt("iIntro", 1); //Adds 1 to iIntro everytime this timer starts
float thisnow = 1.0f; //sets default time for parts: 1 second
switch (GetLocalVarInt("iIntro")) //looks for value of timer
{
case 1: //what it does if the value for iIntro is 1
thisnow = 2.0f;
FadeIn(5);
PlaySoundAtEntity("", "scare_male_terrified.snt", "player", 0, false);
break;

case 2: //if iIntro value is 2
thisnow = .1f;
CreateParticleSystemAtEntity("", "ps_rose_petals_swirl", "player", false);
break;
}
if (GetLocalVarInt("iIntro") <2) //if iIntro value is less than two
{
AddTimer("IntroTimer", thisnow, "Intro");
}
}

void OnEnter()
{
PreloadParticleSystem("ps_rose_petals_swirl");
PreloadSound("scare_male_terrified");
}

(This post was last modified: 08-12-2011, 01:36 PM by Khyrpa.)
08-12-2011, 01:30 PM
Find
rybray Offline
Junior Member

Posts: 31
Threads: 9
Joined: Aug 2011
Reputation: 1
#4
RE: Sequencing Events and Timers

Thank you for the help. Khyrpa, what is the benefit of preloading a sound or particle system? Would they not have appeared at all if I had not preloaded them, or would there have been some sort of error?
08-12-2011, 04:46 PM
Find
Khyrpa Offline
Senior Member

Posts: 638
Threads: 10
Joined: Apr 2011
Reputation: 24
#5
RE: Sequencing Events and Timers

(08-12-2011, 04:46 PM)rybray Wrote: Thank you for the help. Khyrpa, what is the benefit of preloading a sound or particle system? Would they not have appeared at all if I had not preloaded them, or would there have been some sort of error?

Its just that when theyre not preloaded, I'm not sure rly, but I think your computer loads them when they are spawned. Meaning it may cause some lag when they load.

08-12-2011, 08:08 PM
Find




Users browsing this thread: 1 Guest(s)