Newbie Troubles with Playing Sounds

Post » Thu Jun 21, 2012 3:21 pm

I've skimmed around all over and I can't seem to find what I'm doing wrong with this script. I just started delving into Papyrus tonight and my coding background is minimal so it could be an extremely obvious mistake.

I have a large object with a trigger around it (I have tested the trigger by adding text outputs if the trigger successfully..triggers, and it appears the trigger is in working order so that should not be the problem) and I am trying to get a sound to play when the player steps into the trigger.

Here is what I have:


Scriptname ExampleTrigger extends ObjectReferenceimport soundsound property NPC_Dragon_Kill_Roar_A autoEvent OnTriggerEnter(ObjectReference akActionRef)	   if(akActionRef == Game.GetPlayer())			  NPC_Dragon_Kill_Roar_A.play(self)	   endifEndEvent

The actual sound file is NPC_Dragon_Kill_Roar_A.wav but the display name is just NPCDragonKillRoarA. I'm not sure if this is the direct problem, as I've tried putting both.

Any help is appreciated.
User avatar
Natalie J Webster
 
Posts: 3488
Joined: Tue Jul 25, 2006 1:35 pm

Post » Thu Jun 21, 2012 10:11 pm

Hi Astralogic, I'm new to sounds myself, but not scripting and I'm curious about using sounds as I'll be doing that very soon. So I'm sorry if I ask questions that end up not being relevant :wink:

First, have you looked at the return value when playing that sound? When I look at the CK on http://www.creationkit.com/Play_-_Sound, I see there is a return value, so if you see that a zero is being returned, you know it's failing right there.

So, extending the example on that link, try:
int instanceID = mySFX.play(self)		  ; play mySFX sound from my selfSound.SetInstanceVolume(instanceID, 0.5)		 ; play at half volumeDebug.Messagebox("ReturnValue="http://forums.bethsoft.com/topic/1385122-newbie-troubles-with-playing-sounds/+ instanceID)

The other thing, how is it set up in the CK? Did you create a Sound Descriptor? (I needed to for a power I gave an FX, but not sure if you needed to.) With the Sound Descriptor, you can play the sound - so wondering if that works for you? I also found this link: http://www.creationkit.com/Sound_effects_dont_play_in_CK
User avatar
phil walsh
 
Posts: 3317
Joined: Wed May 16, 2007 8:46 pm

Post » Thu Jun 21, 2012 10:04 pm

Easiest way to test if this is working is try having the sound play from the the player rather than the trigger. Some sounds have a very short audible range and don't seem to work properly when played from non-actors. Try

NPC_Dragon_Kill_Roar_A.Play(Game.GetPlayer())

and see if it plays that way.

Edit: Ninja'd by Sollar, and he's right, make sure the Play command is returning a non-zero number. And, since you said you're new to scripting, I'll tell you to make sure you actually assigned the appropriate sound to the NPC_Dragon_Kill_Roar_A property :wink: Just naming it isn't sufficient, you must assign the sound to it in the Properties window.

Edit of the edit: Upon doing some digging, I see the problem. The Sound property wants Sound Markers, not Sound Descriptors, and there is no NPCDragonKillRoarA Sound Marker. You'll either need to create one that references the NPCDragonKillRoarA Sound Descriptor, or use an existing Sound Marker. Either way, I suspect you forgot to assign the Sound property in the Properties window, as you would have noticed the sound you were looking for was missing from the list :smile:

If you want to create a new Sound Marker, this is pretty easy to do. Just right-click the Sound Markers list in the Object Window, choose New, pick the Sound Descriptor you want (NPCDragonKillRoarA) from the dropdown list, and name your new Sound Marker NPCDragonKillRoarA_SM or something like that. Now assign THAT to your Sound property and you should be golden.
User avatar
M!KkI
 
Posts: 3401
Joined: Sun Jul 16, 2006 7:50 am

Post » Fri Jun 22, 2012 3:04 am

I am trying both of your suggestions real quick, I'll have results in a minute. Thank you!

Edit: The value returned was, in fact, zero. I'm not sure where to go from there. I'll try a few changes real quick.
User avatar
Kay O'Hara
 
Posts: 3366
Joined: Sun Jan 14, 2007 8:04 pm

Post » Thu Jun 21, 2012 2:29 pm

As Verteiron suggested, I'd make sure you have the property set up correctly . That seems a very likely problem. I haven't passed a sound effect to a script yet, so I'm not sure how it looks to help you there.
User avatar
Emma Copeland
 
Posts: 3383
Joined: Sat Jul 01, 2006 12:37 am

Post » Thu Jun 21, 2012 4:15 pm

This is where I am at after the above changes:

Scriptname ExampleTrigger extends ObjectReferenceimport soundimport debugsound property NPCDragonKillRoarA autoEvent OnTriggerEnter(ObjectReference akActionRef)	 if(akActionRef == Game.GetPlayer())		  int instanceID = NPCDragonKillRoarA.play(Game.GetPlayer())		  Sound.SetInstanceVolume(instanceID, 0.5)		  Debug.Messagebox("ReturnValue="http://forums.bethsoft.com/topic/1385122-newbie-troubles-with-playing-sounds/+ instanceID)	 endifEndEvent

With no luck and no change. I've tried other sound files as well, with no luck.

I'll check the properties and make sure they line up correctly.
User avatar
Ludivine Poussineau
 
Posts: 3353
Joined: Fri Mar 30, 2007 2:49 pm

Post » Thu Jun 21, 2012 5:27 pm

I edited my post to include a more likely cause to the problem. I use sound properties a LOT in my scripts so this is something I've run into frequently. The Sound Marker vs Sound Descriptor thing is irritating, but you'll get it running!
User avatar
Kayla Bee
 
Posts: 3349
Joined: Fri Aug 24, 2007 5:34 pm

Post » Thu Jun 21, 2012 7:22 pm

I honestly had no idea how to work the properties window or what it meant in relation to the script just a moment ago, but I poked around with it and after reading your re-edit, it appears to line up with what I figured. I changed the audio file to NPCDragonFlightRoar, which I was able to find in the list. Still not sure if I did it 100% correctly, so here is what I have:

i.imgur(dot)com/SvJAC(dot)png

Spoiler
Scriptname ExampleTrigger extends ObjectReferenceimport soundimport debugsound property NPCDragonFlightRoar autoEvent OnTriggerEnter(ObjectReference akActionRef)	 if(akActionRef == Game.GetPlayer())		  int instanceID = NPCDragonFlightRoar.play(Game.GetPlayer())		  Sound.SetInstanceVolume(instanceID, 0.5)		  Debug.Messagebox("ReturnValue="http://forums.bethsoft.com/topic/1385122-newbie-troubles-with-playing-sounds/+ instanceID)	 endifEndEvent

It is still returning a zero.
User avatar
Karl harris
 
Posts: 3423
Joined: Thu May 17, 2007 3:17 pm

Post » Thu Jun 21, 2012 10:54 pm

Property changes don't "take" until you've backed out of the Script edit window and Saved your entire mod, so make sure you've done that... I believe what you have there should be working, or at least returning a non-zero value.
User avatar
Chloe Lou
 
Posts: 3476
Joined: Sat Nov 04, 2006 2:08 am

Post » Fri Jun 22, 2012 4:45 am

I changed it and saved/opened up the game and it returned a zero, but after going back into the CK it appeared the change just didn't stick. After going through it again, it returned a value of 94 and gave me a roar.

Thank you both for the help.
User avatar
sw1ss
 
Posts: 3461
Joined: Wed Nov 28, 2007 8:02 pm

Post » Fri Jun 22, 2012 4:45 am

Nice Verteiron! I learned some good info!

Edit:
Oh, and btw Astralogic, you don't have to use:
import debug

It's just so you won't have to type the "Debug" part... (it's not like other languages where you actually have to load those libraries to use the functions.
User avatar
Imy Davies
 
Posts: 3479
Joined: Fri Jul 14, 2006 6:42 pm

Post » Thu Jun 21, 2012 10:10 pm

AWESOME! Now you can try playing it from your object instead of the Player and see if it still sounds right. And just FYI, sounds play at full volume by default, so unless you want it quieter, you can skip the SetInstanceVolume function.

Glad you got it working!
User avatar
Stat Wrecker
 
Posts: 3511
Joined: Mon Sep 24, 2007 6:14 am

Post » Thu Jun 21, 2012 12:41 pm

Nice Verteiron! I learned some good info!

Edit:
Oh, and btw Astralogic, you don't have to use:
import debug

It's just so you won't have to type the "Debug" part... (it's not like other languages where you actually have to load those libraries to use the functions.

I figured, from the little knowledge of Java I have.

Is there any quick and easy way to play multiple sounds from one event trigger but have them delayed on a custom timer? If not, I'll just figure it out later.

I know that there is a "PlayAndWait" function, but I'm not completely sure it would work.
User avatar
Jennifer May
 
Posts: 3376
Joined: Thu Aug 16, 2007 3:51 pm

Post » Thu Jun 21, 2012 8:04 pm

Well you could use something like

FirstSound.Play(TriggerObject)Utility.Wait(0.6) ; Or however long the sound is + custom wait timeSecondSound.Play(TriggerObject)Utility.Wait(0.4)ThirdSound.Play(TriggerObject)

That the sort of thing you're looking for? I've not used PlayAndWait, but the Wiki says it waits the exact duration of the sound, which may or may not be what you want to do.
User avatar
Trista Jim
 
Posts: 3308
Joined: Sat Aug 25, 2007 10:39 pm

Post » Thu Jun 21, 2012 9:34 pm

Well you could use something like

FirstSound.Play(TriggerObject)Utility.Wait(0.6) ; Or however long the sound is + custom wait timeSecondSound.Play(TriggerObject)Utility.Wait(0.4)ThirdSound.Play(TriggerObject)

That the sort of thing you're looking for? I've not used PlayAndWait, but the Wiki says it waits the exact duration of the sound, which may or may not be what you want to do.

I wasn't aware there is a function for pausing. That should be perfect. Thanks again.
User avatar
Natasha Callaghan
 
Posts: 3523
Joined: Sat Dec 09, 2006 7:44 pm

Post » Thu Jun 21, 2012 2:20 pm

Do yourself a favor and look up Game Script and Utility Script on the CK Wiki. Math Script, too, if you think you'll need trig functions. Just glance through the available functions. There's a lot of "Oh wow, that's kind of cool" functions available. Just glancing through will help you to think, when you need it, "Hmm, I KNOW there was a function for this..."

There are also some surprising gaps, but that's another post :P
User avatar
Myles
 
Posts: 3341
Joined: Sun Oct 21, 2007 12:52 pm


Return to V - Skyrim