Play sound once on button clicks

Get help using Construct 2

Post » Sat Nov 07, 2015 2:10 pm

Message: SteveKane can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
I've created a button that plays a sound when clicked, and it works fine but i wanted it so that the sound will only play once, even if the button has been clicked several times during the sound playing and the only when the current sound has finished can the sound play again.

I've seen a few threads on here regarding audio playing once, and they've all been fixed by using the 'trigger once' condition, but this hasn't worked for me.

Right now, if i continiously press the sound button, the sound will constantly play, which i understand it will do normally. I added a 'trigger once' condition hoping this would fix the issue, but it hasn't worked.

I'm sure i'm missing something obvious but would appriciate help on this.

https://www.dropbox.com/s/3hc55wysgapc0gr/example.capx?dl=0

Thanks
B
5
S
2
Posts: 116
Reputation: 867

Post » Sat Nov 07, 2015 2:20 pm

Add an Audio is tag playing condition to the button clicked event and invert it..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Nov 07, 2015 2:26 pm

Or you could make a global variable that tracks if the button was clicked, where on its first click, it'll set it to 1 and allow a song to play, but if you click again, it is set to 2 and won't play.

Try "On button clicked -> Sys: Add 1 to variable -> | if variable = 1 -> play sound"
B
12
S
3
Posts: 68
Reputation: 906

Post » Sat Nov 07, 2015 2:31 pm

TechnoBeaver wrote:Or you could make a global variable that tracks if the button was clicked, where on its first click, it'll set it to 1 and allow a song to play, but if you click again, it is set to 2 and won't play.

Try "On button clicked -> Sys: Add 1 to variable -> | if variable = 1 -> play sound"


That would make it nescessary to add a second event to set the variable back on sound end, because he wants the sound to be playable again when ended..
Just using one condition and not adding a variable seems a lot easier..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Nov 07, 2015 2:34 pm

@LittleStain Thank you, your solution worked. Seems so simple :)

@TechnoBeaver Thanks for replying, appriciate it.
B
5
S
2
Posts: 116
Reputation: 867


Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot], unicornspitfire and 8 guests