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
[SOLVED] RemoveTimer doesn't work
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#1
[SOLVED] RemoveTimer doesn't work

Yea so i have the timer:



void cry_1_timer(string &in asTimer)
{
PlaySoundAtEntity("", "12_girl_cry", "mansion_5", 0.5f, false);
AddTimer("girl_cry", 40, "cry_1_timer");
}

This timer triggers itself

This next script should remove the timer, but instead, nothing happens. The girl keeps crying.


void girl_flee_stop_timer(string &in asTimer)
{
PlaySoundAtEntity("", "door_level_wood_open", "level_wood_1", 0, false);
RemoveTimer("girl_cry");
StopSound("12_girl_cry", 0);
}

Why won't it stop?

The PlaySoundAtEntity("", "door_level_wood_open", "level_wood_1", 0, false); is working fine!

It's only the timer that doesn't stop

Trying is the first step to success.
(This post was last modified: 05-24-2012, 03:03 PM by FlawlessHappiness.)
05-20-2012, 06:41 PM
Find
Putmalk Offline
Senior Member

Posts: 290
Threads: 13
Joined: Apr 2012
Reputation: 15
#2
RE: RemoveTimer doesn't work

Okay, I see it.

StopSound isn't stopping the correct sound. That's because you left your sound name blank (a practice I HIGHLY do not recommend, because then problems like this are so easy to happen).

Rewrite your sound function like this:
PlaySoundAtEntity("girlcry", "12_girl_cry", "mansion_5", 0.5f, false);


Then, StopSound("girlcry", 0); will work.

And start naming your sounds and callbacks. That will make problems like this easier to avoid as well as make your scripts easier to understand. Just name them simply so you can understand them. Just note that only certain functions support names, like PlaySound..., CreateParticleSystem..., AddUseItemCallback, AddTimer, etc.

Hope this helps!

(This post was last modified: 05-20-2012, 07:30 PM by Putmalk.)
05-20-2012, 07:29 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#3
RE: RemoveTimer doesn't work

No, your script is calling a loop which is basically two timers in this case. You have to add two RemoveTimers. Like this:

void girl_flee_stop_timer(string &in asTimer)
{
PlaySoundAtEntity("", "door_level_wood_open", "level_wood_1", 0, false);
RemoveTimer("girl_cry");
RemoveTimer("cry_1_timer");
}
(This post was last modified: 05-20-2012, 07:36 PM by Statyk.)
05-20-2012, 07:36 PM
Find
Cranky Old Man Offline
Posting Freak

Posts: 986
Threads: 20
Joined: Apr 2012
Reputation: 38
#4
RE: RemoveTimer doesn't work

He never calls girl_flee_stop_timer().

Noob scripting tutorial: From Noob to Pro

05-20-2012, 07:54 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#5
RE: RemoveTimer doesn't work

(05-20-2012, 07:54 PM)Cranky Old Man Wrote: He never calls girl_flee_stop_timer().
My assumption was that he has a timer somewhere in the script that he did not put in the info... If this is the case:

[Image: tactical_facepalm.jpg]
05-20-2012, 07:59 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#6
RE: RemoveTimer doesn't work

Ok sorry Smile Ill post the whole script Wink

void OnStart()
{


AddUseItemCallback("", "crowbar_guestroom", "mansion_7", "UsedCrowbarOnDoor", true);
AddEntityCollideCallback("crowbar_guestroom_joint", "crowbar1_script", "CollideAreaBreakDoor", true, 1);


AddTimer("", 30, "cry_1_timer");

}


void UsedCrowbarOnDoor(string &in asItem, string &in asEntity)
{
AddTimer("", 0.2, "TimerSwitchShovel");
RemoveItem("crowbar_guestroom");
}


void TimerSwitchShovel(string &in asTimer)
{
PlaySoundAtEntity("","puzzle_place_jar.snt", "mansion_7", 0, false);
SetEntityActive("crowbar_guestroom_joint", true);
}


void CollideAreaBreakDoor(string &in asParent, string &in asChild, int alState)
{
AddPlayerSanity(5);
SetSwingDoorLocked("mansion_7", false, true);
AddPropImpulse("mansion_7", 0, 0, -50, "World");
SetSwingDoorDisableAutoClose("mansion_7", true);
SetSwingDoorClosed("mansion_7", false, false);
SetMoveObjectState("mansion_7", 1);
PlaySoundAtEntity("","break_wood_metal", "crowbar1_area", 0, false);
CreateParticleSystemAtEntity("", "ps_hit_wood", "crowbar1_area", false);
SetEntityActive("crowbar_guestroom_joint", false);
SetLocalVarInt("Door", 1);
SetEntityActive("crowbar_guestroom_broken", true);

AddTimer("", 1, "girl_scream_timer");
}

///SCARES

void girl_scream_timer(string &in asTimer)
{
PlaySoundAtEntity("", "12_girl_scream", "level_wood_1", 0, false);
AddTimer("", 2, "girl_flee_timer");
}

void girl_flee_timer(string &in asTimer)
{
SetSwingDoorLocked("mansion_5", false, true);
SetSwingDoorDisableAutoClose("mansion_5", true);
AddPropImpulse("mansion_5", 0, 0, 20, "");
AddTimer("", 1, "girl_flee_stop_timer");
}

void girl_flee_stop_timer(string &in asTimer)
{
PlaySoundAtEntity("", "door_level_wood_open", "level_wood_1", 0, false);
SetGlobalVarInt("Cellar", 1);
RemoveTimer("girl_cry");
StopSound("12_girl_cry", 0);
}

///TIMERS

void cry_1_timer(string &in asTimer)
{
PlaySoundAtEntity("", "12_girl_cry", "mansion_5", 0.5f, false);
AddTimer("girl_cry", 40, "cry_1_timer");
}

EDIT: And no it doesn't work Sad

Trying is the first step to success.
(This post was last modified: 05-22-2012, 07:40 AM by FlawlessHappiness.)
05-20-2012, 08:01 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#7
RE: RemoveTimer doesn't work

Sorry for bumping, but i just can't make this work Sad Everything else than removing the timer is working.. My script is above this post

Trying is the first step to success.
05-24-2012, 09:35 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#8
RE: RemoveTimer doesn't work

You still have not followed the advise posted in post #2.

Tutorials: From Noob to Pro
05-24-2012, 10:32 AM
Website Find
Acies Offline
Posting Freak

Posts: 1,643
Threads: 60
Joined: Feb 2011
Reputation: 73
#9
RE: RemoveTimer doesn't work

void girl_flee_stop_timer(string &in asTimer)
{
PlaySoundAtEntity("", "door_level_wood_open", "level_wood_1", 0, false);
SetGlobalVarInt("Cellar", 1);
RemoveTimer("girl_cry");
StopSound("12_girl_cry", 0);
}

///TIMERS

void cry_1_timer(string &in asTimer)
{
PlaySoundAtEntity("", "12_girl_cry", "mansion_5", 0.5f, false);
AddTimer("girl_cry", 40, "cry_1_timer");
}
(05-20-2012, 07:29 PM)Putmalk Wrote: Okay, I see it.



StopSound isn't stopping the correct sound. That's because you left your sound name blank (a practice I HIGHLY do not recommend, because then problems like this are so easy to happen).



Rewrite your sound function like this:

PlaySoundAtEntity("girlcry", "12_girl_cry", "mansion_5", 0.5f, false);





Then, StopSound("girlcry", 0); will work.



And start naming your sounds and callbacks. That will make problems like this easier to avoid as well as make your scripts easier to understand. Just name them simply so you can understand them. Just note that only certain functions support names, like PlaySound..., CreateParticleSystem..., AddUseItemCallback, AddTimer, etc.



Hope this helps!
Why don't you read your advice boy?

PlaySoundAtEntity("girlcry", "12_girl_cry", "mansion_5", 0.5f, false);

Naming goes here ^

[Image: mZiYnxe.png]


05-24-2012, 10:32 AM
Find
Cranky Old Man Offline
Posting Freak

Posts: 986
Threads: 20
Joined: Apr 2012
Reputation: 38
#10
RE: RemoveTimer doesn't work

(05-20-2012, 07:59 PM)Statyk Wrote:
(05-20-2012, 07:54 PM)Cranky Old Man Wrote: He never calls girl_flee_stop_timer().
My assumption was that he has a timer somewhere in the script that he did not put in the info... If this is the case:
tactical_facepalm.jpg
Sorry. Sometimes I just hastily stick my head in a thread and post the first thing I find. After properly pinpointing the problem, I agreee with your advice.

Noob scripting tutorial: From Noob to Pro

05-24-2012, 12:49 PM
Find




Users browsing this thread: 1 Guest(s)