Author Topic: Scripting sounds  (Read 3199 times)

LeslieWooddavis

  • Newbie
  • *
  • Posts: 3
Scripting sounds
« on: July 10, 2010, 06:32:24 PM »
I am a former HyperCard games designer (Uncle Fudd's Treasure, Clue and others). I would like to assign (via script) a sound to a button. Using hypercard I would simply put: play "frog" 2 times. What would be the comparable script in HyperNext?

I have already added several sounds (.aiff and .wav) to the sound library of my current project. I have no trouble adding and playing one of my sounds via the Sounds: on the Properties Menu, so I know they are there and they work. How do I get the same sounds to cooperate by script? I am a bit confused by your SoundPlay(channel,filename) directions. For one, I have no idea what the channel is or where to find it. I have tried SoundPlay(1,frog), and( 2,frog) (3,frog) (4,frog) (5,frog) since you mentioned that there are five dedicated sound channels in HyperNext. What am I doing wrong?

Help?
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 412
  • Here to help you
Re: Scripting sounds
« Reply #1 on: July 12, 2010, 06:52:36 AM »
I'm sorry for the delay in replying.

The sound play command in HyperNext is not as flexible as the Hypercard command as it only plays the sound either once or loops it.

There are two ways that come to mind for playing a sound immediately after another sound ends.

(1) The best way is to use a timer and let your button trigger it. The timer fires every 50mS or whatever and checks to see if the current sound has stopped playing and if so then starts the next sound. This approach allows other events to occur.

Assume a Timer 1 on the card is being used. There is also a global timer if you need to change change cards while playing sound sequences.

Put this script in your button:-

Code: [Select]
SoundPlay(1,'jungle.wav')
TimerSet(1,2,50)

Put this script in the timer:-

Code: [Select]
Local playing

Put SoundIsPlayingFN(1) into playing
If playing=0 Then
    SoundPlay(1,'thunder_1.wav')
    TimerOff(1)
EndIf

This approach used with the Main Timer could be used to make a sound handler for sequencing sounds.

(2) If you don't mind other events being delayed until your sound sequence ends then put this script in your button:

Code: [Select]
Local playing

SoundPlay(1,'jungle.wav')

Put SoundIsPlayingFN(1) into playing
While (playing=1)
    Put SoundIsPlayingFN(1) into playing
EndWhile

SoundPlay(1,'thunder_1.wav')

Note that the While loop prevents other HyperNext threads from running. if you need to allow background events then the DoEvents command can be placed inside the While loop.


About the sound files and their location. The SoundPlay command expects the sound file to be in the folder or a sub folder of the project/application. The SoundPlayAbs uses an absolute path so the sound can be anyway on the disk etc.
In the above code examples the two sounds were just inside the project folder.

I'm not sure why your sounds are not playing. Perhaps the sound command cannot find them or perhaps their format is wrong.

By the way. The Sound Library is basically there for assigning sounds movies etc to card controls at Design time and assumes the media will not be changed. If you need things changing during Runtime then dynamic commands like SoundPlay are better.
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

LeslieWooddavis

  • Newbie
  • *
  • Posts: 3
Re: Scripting sounds
« Reply #2 on: July 12, 2010, 07:46:24 AM »
Thanks Malkom -

I'll give all your suggestions a shot and let you know how they work. As I'm sure you've noticed by now, I've been asking a great many scripting questions about your program. I am thoroughly enjoying HyperNext despite my confusion in some areas. After I streamline Clue, I'll be updating Uncle Fudd's Treasure (it was originally written in Black and White, so I'll be at this for a long time. Just tell me to back off when you start getting tired of my queries.

Leslie
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 412
  • Here to help you
Re: Scripting sounds
« Reply #3 on: July 12, 2010, 09:00:24 AM »
Leslie, many thanks for your queries because without queries the forums are not much use. Plus your queries are really interesting and practical ones that many of us will find enlightening.

Malkom
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

 

anything