issues with object instances

Get help using Construct 2

Post » Tue Aug 27, 2013 12:24 am

Hello all,

I have a lyout where I have 7 instances of a play button. Each one has a UID assigned to it but I cant figure out how to arrange the Touch (or Click) with the system events to play a given audio track when one of the play buttons is clicked.

For example the top most play button has a UID of 41 and I want it to play "audioTrack1" when the player clicks it. Likewise the 7th instance of the play button has a UID of 48...and when the player clicks it I want it to first stop any music that is playing then pay track "audioTrack7".

This is a simplified example of what I am trying to do...but if someone can help me get this straight I can experiment till it does exactly what I want it to do with other things (like repeating the track...or running through all seven tracks like a playlist).

I would greatly appreciate either a discription of how the event sheet should look or an example. I have looked in the forums and at the tutorials and it seems like everyone is trying to do more complicated things than I am and I cant seem to figure out this relatively simple task.
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Tue Aug 27, 2013 12:35 am

Rather than use the uid why not use an instance variable?
You can give the object one variable, and give each instance a different value.
Then when you click the instance, compare its variable in a sub event.
Image ImageImage
B
168
S
50
G
163
Posts: 8,220
Reputation: 105,059

Post » Tue Aug 27, 2013 1:07 am

As long as it accomplishes the task I am up for it. Though I am a little confused as to HOW to do that.

B
11
S
2
Posts: 65
Reputation: 1,396

Post » Tue Aug 27, 2013 1:20 am

Do I add an instance variable to each one of the play buttons and assign it a number somehow? Then reference that number in the event sheet with an on-click of the general play sprite?
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Tue Aug 27, 2013 1:33 am

Add one variable, they will all have it.
Click on each separately and change each instances value.
Then in events add an event for each instance that you want to compare.
Like: if object is clicked compare object.variable= 1 do this
if object is clicked compare object.variable= 2 do that
if object is clicked compare object.variable= 3 do foo
Image ImageImage
B
168
S
50
G
163
Posts: 8,220
Reputation: 105,059

Post » Tue Aug 27, 2013 7:22 pm

That did it. Thank you Newt.
B
11
S
2
Posts: 65
Reputation: 1,396

Post » Tue Aug 27, 2013 9:14 pm

ok next issue: I have the proper sound file playing when you click the corresponding play Icon (thanks to newt and the uniquely assigned instance variable). I even managed to get any other tracks that were playing to stop before the new one starts playing...(what I mean is that if you click the top most play button...get half way through the track and then decide to listen to the track associated with the play Icon 3 down...the music that was playing for play button one stops and the music for play button 3 plays.

Now what I am trying to do is have the play button sprite for the currently selected track switch to the next frame (a "stop" icon). Which when clicked actually stops the track. Additionally, if I switch to another track I need the sprite for the song that was just playing (ans is on the "stop" frame to revert back to the "play" frame.

I understand how to do all this if I had seperate play sprites but I know that is terribly wasteful. If I could get some more help understanding all this my code would be far more efficient and my project size smaller.

This is what I have at present:

Ontouched PlayIcon
     System|PlayIcon.PlayButton=0|Aduio|Stop all
                                 |PlayIcon|Set animation frame to 1
                                 |Audio|PlayTrack1
     System|PlayIcon.PlayButton=1|Aduio|Stop all
                                 |PlayIcon|Set animation frame to 1
                                 |Audio|PlayTrack2
     System|PlayIcon.PlayButton=2|Aduio|Stop all
                                 |PlayIcon|Set animation frame to 1
                                 |Audio|PlayTrack3

This setup means that the tracks play as they should...but the Play Icon for anything I have "touched" is left at frame 2 (the stop button) and I cant actually stop the tracks from playing unless I click another track to play. I am sure there is something easy I am missing here...so any help would be appreciated.
B
11
S
2
Posts: 65
Reputation: 1,396


Return to How do I....?

Who is online

Users browsing this forum: ksiads and 1 guest