Frictional Games Forum (read-only)

Full Version: [SOLVED] RemoveTimer doesn't work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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
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!
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");
}
He never calls girl_flee_stop_timer().
(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]
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
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
You still have not followed the advise posted in post #2.
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 ^
(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.
Pages: 1 2