Source language: Translate to:

Play sound or not without if routine - something to share...

NeoBook tips, tricks, code samples and more...

Moderator: Neosoft Support

Play sound or not without if routine - something to share...

Postby cipolla » Sat Jan 24, 2004 5:05 am

Hi folks,

here is a small tip to play a sound or not.

The target of a good and small programm is also to save as much as possible code lines.

In many cases it is nice to give the user the choice to play a sound or music or not.

so the normal way would be:
make a checkbox for the sound with a var like [PlaySound]

and the code could be:
[color=green]
If "[PlaySound]" "=" "Checked"
 PlaySoundFile "sound.wav" "NORMAL"
EndIf
[color=black]
If you have many buttons in your pub with a "click-sound" you could copy and paste this in the
action section for each button.

Here is a smaller solution:

Place this in the Check box properties when the user cklicks:
[color=green]
If "[Checkbox]" "=" "Checked"
 SetVar "[Sound]" ""
Else
 SetVar "[Sound]" "No"
EndIf
[color=black]
In your code you only need:
[color=green]
PlaySoundFile "[Sound]sound.wav" "NORMAL"
[color=black]
So if the var [sound] is "no" the action above will result in an error (make sure you have no sound named "nosound.wav") and no sound will be played.

Normaly when you finish a pub you will set the "Display Error Messages" off so no error message will appear.

If you need to diplay the error message for any reason simply make a empty wave file and name it "nosound.wav"

Greetings
Klaus
cipolla
 

Play sound or not without if routine

Postby GKCS » Sat Jan 24, 2004 5:48 am

Klaus,

outside NB:   RENAME XYZ.WAV CHECKED.WAV

inside NB  :    PlaySoundFile "[CheckBoxVariable].WAV" "NORMAL"

and no additional code is necessary ....

G-)
GKCS
 

Play sound or not without if routine

Postby cipolla » Sat Jan 24, 2004 6:26 am

GKCS,

That is true and another good tip.

But by and by it would be a little bit boring to have only one sound in your pub. ;)

If you have more, and that is most normal, like alert.wav, ok.wav, cklick.wav etc.

you can´t handle that with the checkbox var.

Klaus

(Edited by cipolla at 8:48 am on Jan. 24, 2004)
cipolla
 

Play sound or not without if routine

Postby GKCS » Sat Jan 24, 2004 7:22 am

Klaus,

you CAN handle ....... just use the [SELF] variable to make every checkbox and every wav unique .....

PlaySoundFile "[Self][CheckBoxVariable].WAV" "NORMAL"

also would enable usage of different wav files. If the PlaySound action is NO part of the CheckBox-Action itself, you have to use a temp-variable to save the actual triggered object.

G-))

p.s. and don´t forget to rename the wav-files in the expected way

(Edited by GKCS at 9:24 am on Jan. 24, 2004)


(Edited by GKCS at 9:40 am on Jan. 24, 2004)
GKCS
 

Play sound or not without if routine

Postby cipolla » Sat Jan 24, 2004 7:43 am

hmm,

i can´t follow you.

First, why should the PlaySound command be part of the checkbox? the checkbox is only needed to choose whether sound will be played or not (Global in the pub).

lets say i have a button named "okbutton"

i mark the checkbox so the [CheckBoxVariable] is "Checked".

Than in the button action code i use your code:
[color=green]
PlaySoundFile "[Self][CheckBoxVariable].WAV" "NORMAL"
[color=black]
which will result in:
[color=green]
PlaySoundFile "okbuttonChecked.WAV" "NORMAL"
[color=black]
So far so good. but now i have two "ok" buttons on my page. since thy can´t have the same name the other one would be named for example as "okbutton2"

And now? i need another wave-file for this second button.

Another example:

in my code i have to play two sounds like this

if you are a winner...
PlaySound ... winner.wav
else
PlaySound ... looser.wav
EndIf

there is no use for the [self] command. or am i wrong?

Klaus
...getting a little bit confused

(Edited by cipolla at 9:46 am on Jan. 24, 2004)
cipolla
 

Play sound or not without if routine

Postby GKCS » Sat Jan 24, 2004 8:00 am

Klaus,

be honest, you are wrong ..... :-)

First, it was your post, where you asked for different WAV files .....

"But by and by it would be a little bit boring to have only one sound in your pub.  "


Now, take your sample:

if you are a winner...
PlaySound ... winner.wav
else
PlaySound ... looser.wav
EndIf

rename the WINNER.WAV into WINNERCHECKED.WAV
rename the LOOSER.WAV into LOOSERCHECKED.WAV

NOW
when you use the PLAYsound outside the CheckBox action, you need, as mentioned, a temporary variable, to save the active CheckBox

Put

SetVar "[CheckBoxObject]" "[Self]

into the CheckBoxAction

and NOW you just use

PlaySoundFile "[CheckBoxObject][CheckBoxVariable].WAV" "NORMAL"

With this, you can use as many sound as you like. All you have to do, is to rename your files in a logical used way .......

G-)))
GKCS
 

Play sound or not without if routine

Postby cipolla » Sat Jan 24, 2004 8:23 am

ok gkcs,

now i know why i was confused about what you said.

It is this thing with the [self] variable. i don´t understand the need for it, but i understand now what you mean.

i don´t need any code in the CheckBox action.

1. I place my (global)CheckBox on my page the var will be [sound]
2. i want a sound like click.wav so i rename it to clickChecked.wav (as you said)
3. Any place in my pub i use

PlaySoundFile "click[sound].WAV" "NORMAL"

If the user unchecks the Checkbox the var [sound] will be empty, the file could not be found an so no sound would be played.

Thats all.

Are we friends now? :)

Here is a small demo to show in round terms what i mean.

http://www.empics24.de/soundtest.zip


(Edited by cipolla at 10:55 am on Jan. 24, 2004)
cipolla
 

Play sound or not without if routine

Postby GKCS » Sat Jan 24, 2004 9:36 am

Hey Klaus,

we never have been "Non-Friends"  :-)

Now you got the basic idea behind. You only use the [Self] variable, in case you use different checkboxes on one page. So, with that trick, you always can see, WHICH CheckBox was used.
Also, in this case you need to temporarily save the CheckBox name , because the [Self] variable also could contain other NON-CheckBox object´s names .....

But as mentioned, you got the idea behind .... and that´s the most important ....

Gerhard
GKCS
 


Return to NeoBook Knowledgebase

Who is online

Users browsing this forum: No registered users and 1 guest