Play Sound File When Counter Reaches Certain Point?

This forum is meant for requesting technical support or reporting bugs.

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

Play Sound File When Counter Reaches Certain Point?

Postby Ikonz101 » Mon Oct 05, 2009 6:48 pm

What code would I use to play a sound file when the time (counter) reaches a certain amount of time? I know this would be a global procedure because it will be the same for every frame. Example:

If Counter = 100 Then
PlaySound GetPath(2) + "blah blah.wav", False
End If

I already have the PLAYSOUND global procedure copied over. I just need the code to execute it when it reaches a certain amount of time. I got it working before but it would only work it you went to one frame and then back to the other frame again. I need it so that the sound will play on any frame at the certain amount of time. If I put the above code: If Counter = 600 Then.... It plays the file fine (Because my countdown timer is set to 600). But that isn't what I want. I want it to play at around 100 or 150.

The soundfile is in the External Folder of my Projects Folder.

Thank You
Ikonz101

EDIT: Man I have tried every different type of coding for this and can't get it to calculate the counter when it reaches a certain time to play a .wav file. Any help would be greatly appreciated. What I am trying to do is that when the time (counter) reaches around a minute it plays a audio file saying "Time Is Running Out".
User avatar
Ikonz101
Frequent Poster
 
Posts: 128
Joined: Wed Nov 28, 2007 11:23 pm

Postby Ikonz101 » Tue Oct 06, 2009 9:04 pm

Any Bidders? :D

Ikonz101

This is the code I am using to get the sound to play when you change frames:

If GetSound = 1 Then
PlaySound GetPath(2) + "running out of time.wav", False
Else
GetSound = 0
End If

If Counter <=600 and Counter =>598 Then
GetSound = 1
End If

Basically it should play the sound when the counter hits 599. It does play it but only if you switch frames. I need it to play the sound when the countdown timer reads "9:59" which is 599. But I just can't get it to work or read the countdown timer.
User avatar
Ikonz101
Frequent Poster
 
Posts: 128
Joined: Wed Nov 28, 2007 11:23 pm

Postby reneuend » Wed Oct 07, 2009 2:08 am

Code: Select all
If GetSound = 1 Then
PlaySound GetPath(2) + "running out of time.wav", False
Else
GetSound = 0
End If

If Counter <=600 and Counter =>598 Then
GetSound = 1
End If



Why not just do this?
Code: Select all
If Counter < 600 and GetSound = 0 then
    PlaySound GetPath(2) + "running out of time.wav", False
    GetSound = 1
End If
---


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

Postby Ikonz101 » Wed Oct 07, 2009 4:22 am

Code: Select all
If Counter < 600 and GetSound = 0 then
    PlaySound GetPath(2) + "running out of time.wav", False
    GetSound = 1
End If


That works perfectly but the only problem is that it doesn't do it instantaneously. Once the countdown timer decreases it won't play it unless you switch frames. I need it to do it while you are in any frame and it reaches that time.

Thank You For The Help
Ikonz101
User avatar
Ikonz101
Frequent Poster
 
Posts: 128
Joined: Wed Nov 28, 2007 11:23 pm

Postby reneuend » Wed Oct 07, 2009 4:51 am

The nice thing about the CreateTimedEvent command is that you can set it so it runs the event continuously by setting the last parameter to True! :)

You'll need to call your routine with the following from the Frame Advanced Properties:
Code: Select all
Action.CreateTimedEvent 0.5, "UpdateCounter", True



Then you'll need to put your routine into a global procedure:
Code: Select all
Sub UpdateCounter()

If Counter < 600 and GetSound = 0 then
    PlaySound GetPath(2) + "running out of time.wav", False
    GetSound = 1
End If

End Sub
[/code]
---


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

Postby Ikonz101 » Wed Oct 07, 2009 5:18 am

Not a surprise it worked perfectly.. Your coding skills are amazing reneuend. Thank you yet again. Sorry for asking for so much help but I am learning more and more about the coding aspect everyday.

Thank You
Ikonz101
User avatar
Ikonz101
Frequent Poster
 
Posts: 128
Joined: Wed Nov 28, 2007 11:23 pm

Postby reneuend » Wed Oct 07, 2009 2:15 pm

Thanks for the compliment.
It's really no problem. This is how I started too! :)
---


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


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests