How to play a sound only if variable=x?

This forum is meant for posting anything related to Adventure Maker that doesn't fit in the other forums.Please post technical questions in the Technical Support Forum!

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

How to play a sound only if variable=x?

Postby Bzyk » Wed Feb 16, 2011 12:51 pm

I need help. I have got one hotspot, which converts variable value on every click. In my game it is a on/off switch. I want it to play sound only if we turn it off.
Luminous beings are we, not this crude matter...
User avatar
Bzyk
Frequent Poster
 
Posts: 142
Joined: Sat Feb 17, 2007 9:49 pm
Location: Poland

Postby reneuend » Thu Feb 17, 2011 3:55 am

I do this kind of thing from VB Script. Is this okay or do you prefer using the Adventure Maker Variables tab?

Either way, you'll be calling a procedure to start the sound and the other to stop it.

Also, do you realize that variables default to 0? This is ok if you intend for the sound to stop playing when the hotspot is first clicked. This also means that you should already be playing the sound - probably from the frame properties.


///// The following goes under the Advanced Tab of the hotspot /////



Code: Select all

'User clicked on the hotspot, so toggle the value of the variable
if play_music = 0 then
    play_music = 1
else
    play_music = 0
end if

'Now decide if the sound should be played
if play_music = 0 then
    PlaySoundWin7 "soundfile", 1, 10
else
    StopSoundWin7 10
end if




///// The following goes in your procedure area //////

Code: Select all
Sub PlaySoundWin7(SoundFile, NumRepeat, ChannelNumber)
   If ChannelNumber < 9 Then
      'With VBScript it is currently not possible to interact with the 8 first audio channels.
      MsgBox "The specified audio channel is invalid.", vbCritical, "Error"
      Exit Sub
   End If
   If Action.IsComponentInstalled("NSPlay.NSPlayCtl.1") = False Then
      MsgBox "Unable to find the media player component.", vbCritical, "Error"
   Else
      If Action.DoesComponentExist("MediaPlayer" + CStr(ChannelNumber)) = false Then
         AddComponent "NSPlay.NSPlayCtl.1", "MediaPlayer" + CStr(ChannelNumber)
      End If
      Component("MediaPlayer" + CStr(ChannelNumber)).Object.FileName = SoundFile
      Component("MediaPlayer" + CStr(ChannelNumber)).Object.PlayCount = NumRepeat
      Component("MediaPlayer" + CStr(ChannelNumber)).Object.Play
   End If
End Sub



Sub StopSoundWin7(ChannelNumber)
   If ChannelNumber < 9 Then
      'With VBScript it is currently not possible to interact with the 8 first audio channels.
      MsgBox "The specified audio channel is invalid.", vbCritical, "Error"
      Exit Sub
   End If
   If Action.DoesComponentExist("MediaPlayer" + CStr(ChannelNumber)) = true Then
      Component("MediaPlayer" + CStr(ChannelNumber)).Object.Stop
   End If
End Sub


---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2691
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby Bzyk » Thu Feb 17, 2011 8:48 am

Thanks! But I don't get it. :( I must do something wrong, because it doesn't work...
Luminous beings are we, not this crude matter...
User avatar
Bzyk
Frequent Poster
 
Posts: 142
Joined: Sat Feb 17, 2007 9:49 pm
Location: Poland

Postby reneuend » Thu Feb 17, 2011 1:30 pm

Did you use something like this to call the sound routine?

Code: Select all
PlaySoundWin7 GetPath(4) & "wolves_howling.wav", 1, 9



- you need GetPath(4) if the sound file is in your Areas folder
- you must use a channel value of 9 or greater
- don't forget the filename
- Did you place the routines in the procedures area? Advanced Tab - Procedure button at the bottom.
- Did you define an integer variable?
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2691
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA


Return to Adventure Maker General Discussion

Who is online

Users browsing this forum: MSN [Bot] and 1 guest

cron