issues with object instances

0 favourites
  • 7 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • 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.

  • 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.

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

  • 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?

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That did it. Thank you Newt.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)