demidekidasu Posted August 18, 2012 Share Posted August 18, 2012 Hi all, I've trying to work my way around a problem I am having with my script almost all day, but I think I need to admit defeat and ask for help. Bassically, I want to be able to stop a looped sound from playing at the press of a key. Here is the particular section which I need help with (using IsKeyPressed from SKSE):Event OnUpdate() If Input.IsKeyPressed(39) == 1 Game.ForceThirdPerson() Game.DisablePlayerControls(True, True, True, False, True, False, True) Utility.wait(2.0) PlayerREF.playidle (IdleLuteStart) Utility.wait(1.0) int instanceID = DDDplaylutesound.Play(PlayerREF) If Input.IsKeyPressed(207) == 1 Sound.StopInstance(instanceID) PlayerREF.playidle (IdleLooseStop) Game.EnablePlayerControls() endif endif endevent Now, the problem here is that in this instance, neither the sound nor the idle anim will stop when I press key 207 (the [End] key). If I put an "else" in there, it will start and stop the anim at the correct key presses, but the script will not compile with the "Sound.StopInstance(instanceID)" there ("variable instanceID is undefined"). It seems to me that I can only use that line if it is in the same sequence as the play command, rather than at the press of a key in a different part of the script. I am sure it must be myself at fault here, but I honestly cannot figure out a solution as my scripting knowledge is really quite limited, and the wiki tends to confuse me a little. I also wonder if there is an alternative way to stop sounds from playing at the press of a key. Massive thank you in advance to anyone who may be able to help or simply explain what I am doing wrong! Link to comment Share on other sites More sharing options...
demidekidasu Posted August 18, 2012 Author Share Posted August 18, 2012 Is it at least even possible? Surely it isn't the case that a sound loop can only be stopped in the same sequence that it starts in, after a timer... I cannot seem to find anything of use to me at all by searching either here, on google or the wiki. It is seriously frustrating and I'm ready to start tearing my hair out here. Link to comment Share on other sites More sharing options...
RandomlyAwesome Posted August 19, 2012 Share Posted August 19, 2012 (edited) I don't have the compiler since this is my laptop so it may not compile but you can try this script: Sound Property LuteSound auto int instanceID1 Event OnUpdate() If Input.IsKeyPressed(39) == 1 Game.ForceThirdPerson() Game.DisablePlayerControls(True, True, True, False, True, False, True) Utility.wait(2.0) PlayerREF.playidle (IdleLuteStart) Utility.wait(1.0) instanceID1 = DDDplaylutesound.Play(PlayerREF) EndIf If Input.IsKeyPressed(207) == 1 Sound.StopInstance(instanceID1) PlayerREF.playidle (IdleLooseStop) Game.EnablePlayerControls() EndIf EndEvent Edited August 19, 2012 by RandomlyAwesome Link to comment Share on other sites More sharing options...
demidekidasu Posted August 19, 2012 Author Share Posted August 19, 2012 Thanks, RandomlyAwesome. It compiles, but does not appear to work in game (I am probably making a mistake). But I think I can mess around with it from here, so a huge thanks and kudos to you! Link to comment Share on other sites More sharing options...
steve40 Posted August 20, 2012 Share Posted August 20, 2012 (edited) I haven't tested this. Sound Property LuteSound auto int instanceID1 bool isPlaying = False Event OnUpdate() UnRegisterForUpdate() If Input.IsKeyPressed(39) == 1 && !isPlaying isPlaying = True Game.ForceThirdPerson() Game.DisablePlayerControls(True, True, True, False, True, False, True) Utility.wait(2.0) PlayerREF.playidle(IdleLuteStart) Utility.wait(1.0) instanceID1 = DDDplaylutesound.Play(PlayerREF) ElseIf Input.IsKeyPressed(207) == 1 && isPlaying If instanceID1 != None Sound.StopInstance(instanceID1) EndIf PlayerREF.playidle(IdleLooseStop) isPlaying = False Game.EnablePlayerControls() EndIf RegisterForSingleUpdate(0.05) EndEvent Edited August 20, 2012 by steve40 Link to comment Share on other sites More sharing options...
Recommended Posts