How do I [AUDIO] - stop sound instance

Get help using Construct 2

Post » Sun Jul 10, 2016 3:52 pm

I have multiple instances of a laser which can be turned on and off.

I am playing a sound loop on each laser positionally. I want to be able to have the sound stop and start per instance of laser instead of a global tag of 'laser' which turns them all off and on.

Any ideas?

I want a flexible system because I've 100 levels with many configurations of these lasers already designed.

Thanks!
B
43
S
13
G
8
Posts: 612
Reputation: 7,372

Post » Sun Jul 10, 2016 4:03 pm

You could convert the UID of the laser to a string and use that as the tag. That would make the tag unique per instance, even for the same sound.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Mon Jul 11, 2016 10:11 am

blackhornet wrote:You could convert the UID of the laser to a string and use that as the tag. That would make the tag unique per instance, even for the same sound.


Ah yeah! Great idea I'll try that tonight :) Thanks so much!
B
43
S
13
G
8
Posts: 612
Reputation: 7,372

Post » Mon Aug 22, 2016 9:58 pm

blackhornet wrote:You could convert the UID of the laser to a string and use that as the tag. That would make the tag unique per instance, even for the same sound.


Just got round to trying this!

Doesn't seem to work as intended - here's my code:

Image

And here's a demo demonstrating what's happening:

https://youtu.be/w4BtLBK4gek

As you can hear, the first object starts playing okay - but when the second activates the sound isn't being positioned on to it and I can't seem to stop the sound.

Any ideas?

Thanks!
B
43
S
13
G
8
Posts: 612
Reputation: 7,372

Post » Mon Aug 22, 2016 11:39 pm

Here's an example of it working. Click on the two sprites to start/stop the sound at each.
http://www.blackhornettechnologies.com/ ... IDTag.capx

I think you are having picking issues. I don't trust Trigger Once. I'd use a flag, like I've done, to actually control the sound. Or you can even see if the sound is playing already, to start/stop.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Tue Aug 23, 2016 12:09 pm

blackhornet wrote:Here's an example of it working. Click on the two sprites to start/stop the sound at each.
http://www.blackhornettechnologies.com/ ... IDTag.capx

I think you are having picking issues. I don't trust Trigger Once. I'd use a flag, like I've done, to actually control the sound. Or you can even see if the sound is playing already, to start/stop.


Yeah I'm really struggling with picking - here's my actual code in the way it makes sense to me:

Image

I can't seem to find a condition that isn't using trigger once to make the sound play only once as the laser, when it's turned off by shooting the button it waits 5 seconds and then switches on again, so I'm using 'isOn' variables etc.
B
43
S
13
G
8
Posts: 612
Reputation: 7,372

Post » Tue Aug 23, 2016 2:22 pm

It's completely unnecessary to try to detect when a variable has changed with 'Trigger once'. You changed the variable, you know when it happened. If the value gets changed in multiple places, then put the code in a function and call the function when the value changes. Or, you may not even need the variable anymore, just call the code.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Wed Aug 24, 2016 3:30 pm

blackhornet wrote:It's completely unnecessary to try to detect when a variable has changed with 'Trigger once'. You changed the variable, you know when it happened. If the value gets changed in multiple places, then put the code in a function and call the function when the value changes. Or, you may not even need the variable anymore, just call the code.


Ah man I'm just not getting this :( I'll upload a capx of what I'm doing if interested. Thanks for all the help by the way!
B
43
S
13
G
8
Posts: 612
Reputation: 7,372

Post » Wed Aug 24, 2016 10:54 pm

You can PM me if you want.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227


Return to How do I....?

Who is online

Users browsing this forum: Darth Crusher and 6 guests