Computer Science Canada

Using Sound in turing

Author:  D_homes [ Sun Nov 08, 2009 1:59 pm ]
Post subject:  Using Sound in turing

What is it you are trying to achieve?
Stop the music file from playing if the variable "ammo" is equal to zero.


What is the problem you are having?
I can't get it to work.


Relevant code

Turing:


    %check to see if mouse is clicked
    if button = 1 then
        delay (100)
        Music.PlayFile ("fire1.wav")
        ammo := ammo - 1
        %If ammo is equal to or less than 0, then it equals 0
        if ammo <= 0 then
            ammo  := 0
        end if
        cls
    end if
    cls



Version of Turing:
4.1.1

Author:  Superskull85 [ Sun Nov 08, 2009 2:27 pm ]
Post subject:  RE:Using Sound in turing

You can use <b>Music.PlayFileStop</b> () to stop the playback of music files. If you want your program to continue while playing music, than use <b>Music.PlayFileReturn</b> (FileName : string) instead of <b>Music.PlayeFile</b> (FileName : string).

Author:  D_homes [ Sun Nov 08, 2009 2:45 pm ]
Post subject:  RE:Using Sound in turing

This still doesnt fix my problem.
Do you mean to change it to this?


if button = 1 then
delay (100)
Music.PlayFileReturn ("fire1.wav")
ammo := ammo - 1

if ammo <= 0 then
Music.PlayFileStop
ammo := 0
end if
cls
end if

I want the .wav to not play when the variable ammo = 0

Author:  D_homes [ Sun Nov 08, 2009 3:29 pm ]
Post subject:  RE:Using Sound in turing

Anyone?

Author:  Tony [ Sun Nov 08, 2009 3:46 pm ]
Post subject:  RE:Using Sound in turing

In your current code, you are playing the sound first, then checking to see if ammo is empty. You probably want to have it the other way around.
code:

if button = 1 then
        if ammo <= 0 then
            ammo  := 0
        else
             Music.PlayFile ("fire1.wav")
             ammo -= 1
        end if
    end if


: