How do I play a sound from an array?

1 favourites
  • 12 posts
From the Asset Store
In this template the music plays without looping in your game
  • I've really wracked my brains on how to try and do this but unfortunately I couldn't find anything. :(

    I want to play a sound once an object is destroyed according to the object's corresponding sound in the array.

    Since I am using a large amount of data, I've had to use advanced shuffle to get the randomisation I'm looking for when the game starts. Thus I'm finding difficulty playing audio the way I want to by the normal Construct 3 conventions, from what I can see so far.

    If you're able to figure it out I'd be more than happy to credit you by mentioning your work or something as well, once this game is released (because this is an extremely huge feature in the game and I would feel super bad if I wasn't able to show my gratitude in one way or another)

    Here is the link to the file of the game: drive.google.com/file/d/1v2L1e-elHwXcZ7vTxdFy56FUQ66gjfjY/view

    You can find the code under '15WordsN5 level' and it's linked to Game Layout.

    If anyone is able to figure this out. You will be my literal hero lol.

  • I'm not seeing any logic that tries to play audio? Also better if you explain more about what's going on in the game.

  • You need to add the audio plugin. After you add it, there is an action "Play (By Name)." Pass the array value into this event.

  • I'm not seeing any logic that tries to play audio? Also better if you explain more about what's going on in the game.

    sorry i thought i saved the audio at least as an object but I didn't . ^^"

    I tried the play function and it was showing me a dropped down list of audio I added which wasn't what I wanted so I didn't want to add that logic in.

    I tried a new method though and saved it but unfortunately it doesn't seem to be working either ._.

    I want to do the following:

    1. Word matches with meaning, it will disappear (which it currently does)

    2. When it disappears, I want the audio of the word to be heard (which is at the 5th column of the array.

    I've also made the words to two pairs to hopefully make it easier for a pair to be matched and make it easier to find out if the audio plays when a pair is successfully matched.

    You need to add the audio plugin. After you add it, there is an action "Play (By Name)." Pass the array value into this event.

    Thank you for the suggestion.

    I think this is up my alley of what I'm looking for but unfortunately its still not working. I've tried to add it in as the following:

  • Doesnt that function just run once at start of layout? You want it to play sounds as they get answers correct then it should go in the drop logic.

  • Doesnt that function just run once at start of layout? You want it to play sounds as they get answers correct then it should go in the drop logic.

    ok, I've put it into the drop logic (when object is destroyed) and it's still not working.

    I changed it into a function in order to call the audio during the time it's destroyed but still no success.

  • Gonna need that file

  • Gonna need that file

    That previous link should show the updated version? If not, please try use this: drive.google.com/file/d/1YYUL2FmeQhySWrP0tRFFZ3lf6DTD7R-6/view

    (also, happy new year!)

  • Your sounds aren't playing because your sound names include the .webm extension. When you use the play by name method, don't include the .webm in the name of the sound. For the game as it is, you don't need to remove all the .webm extensions from the list of sounds. You can just do this:

    -> Audio: Play replace(DataN5.At(5,index), ".webm", "") not looping from Sounds at 0 dB (tag "")

    The replace statement will strip the extension off for you.

  • Your sounds aren't playing because your sound names include the .webm extension. When you use the play by name method, don't include the .webm in the name of the sound. For the game as it is, you don't need to remove all the .webm extensions from the list of sounds. You can just do this:

    -> Audio: Play replace(DataN5.At(5,index), ".webm", "") not looping from Sounds at 0 dB (tag "")

    The replace statement will strip the extension off for you.

    fantastic! this got the audio to work so thank you so much! (and I hope you had a Happy New Year too!)

    However it seems to play a completely irrelevant sound form what it should be corresponding to in the array. Also it repeats the same sound for subsequent words that are matched.

    I'm surmising that maybe it's because it's only preloading audio once?

    But I'm guessing even if I got it to call audio more than once I'll just get random sounds.

    If I could just get the correct audio to play. T_T I'm so glad to hear the audio working when it should be though, thank you!

  • Instead of passing in a result from the AdvancedRandom object to the loadAudio function call, pass in the index value stored in the index variable of the MeaningSprite or WordSprite objects. Without knowing the language, I can tell you that the sound being played seems to be correct. Especially when the word was handkerchief. I believe this will solve your sound problems.

    -> Functions: Call loadAudio (index: MeaningSprites.​Index)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Instead of passing in a result from the AdvancedRandom object to the loadAudio function call, pass in the index value stored in the index variable of the MeaningSprite or WordSprite objects. Without knowing the language, I can tell you that the sound being played seems to be correct. Especially when the word was handkerchief. I believe this will solve your sound problems.

    -> Functions: Call loadAudio (index: MeaningSprites.​Index)

    it's perfect!!! aaah please let me know if you have any projects you'd like me to credit when I release this! if you don't want to mention it here, please feel free to let me know the details at midnparishnz@gmail.com !

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