Having issues making "Sound.StopInstance" work.

Post » Sun May 05, 2013 5:16 am

Greetings!

I am trying via Papyrus to stop a looped sound effect from playing on a certain condition but the script somehow never gets to that part.

Detailed Script Information

The script plays snoring sound effects on actors when they are asleep and stops the sound effects when the actor is awake (Being attacked/killed, talked to or simply finishing sleeping).

The script is attached to an object reference in the same cell as the actor and its properties (Actor, sound to play and two Ints) are defined on the object itself.

The sound effect starts playing fine when the actor goes to sleep, but it won't stop when he's awake. By checking my Papyrus log using the Debug.Trace function, I can see that the script works fine when playing the sound, but the other trace I use when the sound stops does not fire.

Very strange! It was a long time ago, but I recall that it was working fine when I used the infamous RegisterForUpdate, yet RegisterForSingleUpdate should work on the script now.

Here is the script in question:

Scriptname SoSCivSnore extends ObjectReference{Script attached to Render Window hidden object references that allows specific NPCs to play the snore SFX.}Actor Property SnoringActor AutoSound Property SnoringSoundFX AutoInt Property SnoringPlay AutoInt Property CurrentlySnoring AutoEvent OnInit()        RegisterForSingleUpdate(0.5)        GoToState("Snoring")EndEventState Snoring    Event OnUpdate()        If CurrentlySnoring == 0            If (SnoringActor.GetSleepState() == 3)                Debug.Trace("Currently Sleeping")                SnoringPlay = SnoringSoundFX.Play(SnoringActor)                CurrentlySnoring = 1                RegisterForSingleUpdate(0.5)                Return            endif        Endif        If CurrentlySnoring == 1            If (SnoringActor.GetSleepState() != 3)                Debug.Trace("Currently Awake")                Sound.StopInstance(SnoringPlay)                CurrentlySnoring = 0                RegisterForSingleUpdate(0.5)                Return            Endif        Endif    EndEventEndState
User avatar
JAY
 
Posts: 3433
Joined: Fri Sep 14, 2007 6:17 am

Post » Sun May 05, 2013 7:45 am

Your RegisterForSingleUpdate is inside your GetSleepState() != 3 check. That means that if CurrentlySnoring == 1 and GetSleepState() == 3, the script doesn't get re-registered.

User avatar
Lalla Vu
 
Posts: 3411
Joined: Wed Jul 19, 2006 9:40 am

Post » Sun May 05, 2013 5:47 pm

That was indeed the issue!

It works perfectly now.

Thank you for the help Verteiron! :tops:

User avatar
Soku Nyorah
 
Posts: 3413
Joined: Tue Oct 17, 2006 1:25 pm


Return to V - Skyrim