# How do I make some cars play the same sound?

Get help using Construct 2

### » Sun Mar 08, 2015 3:43 pm

The character limit makes it a bit hard to explain my problem in the topic heading.
I'm making an endless-runnner with a car object that you run past from time to time. Basically I want each instance of the car to play a looping sound that starts when the car is first on-screen, becomes louder based on how close Car.x is to scrollx, and stops when the car is no longer on screen. The sound must also be muted and unmuted based on the local value 'sound'.

I've given the Car object a boolean value called 'IsPlayingSound'. If the boolean value is false and the Car is on-screen and the local value 'sound' = 1, then the sound 'Car' is played looping with the tag "Car"&Car.uid.
If the local value 'sound' = 0 (so that the player can mute the sound if it's annoying them) and 'IsPlayingSound' is true, then the boolean is set to false and the tag "Car"&Car.uid is stopped.
If Car is not on-screen and 'IsPlayingSound' is true then set it to false and stop "Car"&Car.uid.
And finally, if Car is on-screen and 'IsPlayingSound' is true then set the volume of "Car"&Car.uid to a little maths equation that makes it louder when Car.x is closer to scrollx.

It all works surprisingly well, apart from when I try to stop the car sound if the local value 'sound' =0. The value can be toggled between 1 and 0 by pressing N so that the sound can be muted by the player.
This works when one car is on-screen, however when more than one car is on-screen then only one of them has the sound stopped while the others continue to play.

I'm sure that this shouldn't happen. If I've written If 'sound' = 0 and Car IsPlayingSound, then set IsPlayingSound to false and stop tag "Car"&Car.uid then surely it should affect every car? It should go through each car which 'isPlayingSound' one by one and set the boolean to false and stop the sound, right?

I could easily solve this problem if sounds could have multiple tags. Every sound would have two tags, "Car"&Car.UID and just "Car". That way I could start, stop and control the volume of each sound using "Car"&Car.UID and I could mute/unmute every sound when the player presses N using "Car".

Except I can't do that be because obviously Construct 2 doesn't support multiple audio tags. So, does anybody know an alternative solution?
B
8
S
1
Posts: 54
Reputation: 824

### » Mon Mar 09, 2015 12:26 am

If 'sound' = 0 and Car IsPlayingSound, and for each car.....then
B
63
S
15
G
6
Posts: 271
Reputation: 12,473

### » Thu Mar 19, 2015 6:05 pm

What the fuck. How have I never noticed this 'for each' thing? This makes everything ever so much easier. Jesus christ.
B
8
S
1
Posts: 54
Reputation: 824

### » Thu Mar 19, 2015 6:12 pm

Does 'for each' mean 'Repeat this action on every single instance of the object' or 'Repeat this action for every instance of the object that fits the conditions'?
B
8
S
1
Posts: 54
Reputation: 824

### » Fri Mar 20, 2015 2:01 am

it depends on the order of the events.. if you put a condition prior to the "for each", it will consider only the ones matching the previous conditions, not all the instances
B
63
S
15
G
6
Posts: 271
Reputation: 12,473

### » Fri Mar 20, 2015 2:02 am

it depends on the order of the events.. if you put a condition prior to the "for each", it will consider only the ones matching the previous conditions, not all the instances
B
63
S
15
G
6
Posts: 271
Reputation: 12,473

### » Sat Mar 21, 2015 11:18 am

Thanks for the help!
B
8
S
1
Posts: 54
Reputation: 824