User Tag List

Results 1 to 7 of 7

Thread: Is it possible to reference / play a sound from a string variable?

  1. #1
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    MTCMusic's Avatar
    Join Date
    Jan 2007
    Location
    Montreal, Canada
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to reference / play a sound from a string variable?

    I'd like to set a sound to play according to a variable value.
    example:
    If X=1, set $sound to "sound1"
    If X=2, set $sound to "sound2"
    etc....

    Play $sound

    I know this is not in the correct syntax, but I hope you can get an idea of what I am trying to do.

    Thanks for any help or suggestion

    Tom

  2. #2
    Clicker

    Join Date
    Jul 2011
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Attachment 13624

    Maybe this will help? The example uses a tree object to list the samples in a directory and then plays them when you click on their name in the list.

    If you meant to play an internal sample from the expression editor, I don't know if you can.

  3. #3
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    MTCMusic's Avatar
    Join Date
    Jan 2007
    Location
    Montreal, Canada
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help Klikplay, but I need to play an internal sample from the expression editor; I have a quiz engine (a group) that will play a sound and the player has to guess that sound. At the tp of my program, I have a random generator that sets a variable to a number between 1 and 10. Depending on the value, the engine should play the corresponding sound. Right now, I have a group for each of the 10 sounds and activate the groupe correspondong to the result from the random number, but I would like to just use 1 group and have it play the sound corresponding to the random number that was generated. This would make the program incredibly smaller and thus faster to load in HTML5.


    Thanks for your help
    Tom

  4. #4
    Clicker

    Join Date
    Jul 2011
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know if this would work for your project, but...

    What if you embedded your sounds in data elements? Then they could be extracted and played at runtime. I think this should allow for you to play them using a string. If you named the files "1.wav","2.wav","3.wav", etc.... you could play them using the string of your random value + ".wav".

    Just a thought.

    /edit/

    Here's an example I tossed together.
    Play3.zip

  5. #5
    Forum Moderator Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jun 2006
    Location
    England
    Posts
    3,512
    Mentioned
    3 Post(s)
    Tagged
    1 Thread(s)
    Two ways to do this using fast loops:

    1. Have multiple loops called "sound1", "sound2", "sound3" each of which played their respective internal sample. Then run "sound"+str$(Global Value A) for one loop to play your given sound.

    2. Have one loop called "play_sound". Then have multiple events checked it being triggered, each checking the global value/string against a different value of Global Value A and playing the respective sample.
    .:::.Joshtek.:::.

  6. #6
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    MTCMusic's Avatar
    Join Date
    Jan 2007
    Location
    Montreal, Canada
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to both of you for the great ideas. I will put them both to the test today and will let you know how it goes. Thanks you very much for the help!

    Tom

  7. #7
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    MTCMusic's Avatar
    Join Date
    Jan 2007
    Location
    Montreal, Canada
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Joshtek: Just wanted to let you know that your first method works perfectly for what I need to do. Thank you for your help. Your name is going into the credits. I'll send you a link to hte finished game once it's online (HTML5).

    THANK YOU VERY MUCH FOR THIS!

    Thanks also to klikhappy; although your method worked just as well, I think I'll have issues with the binaries when I'll put the final product online. But thank you very much for your example; it will come in handy on future projects!

    Tom

Similar Threads

  1. How to play 2 Sound files ?
    By Droggelbecher in forum Android Export Module 2.5
    Replies: 4
    Last Post: 8th January 2014, 02:30 PM
  2. How do you play default ios sound, eg the notification sound.
    By assentec in forum iOS Export Module Version 2.0
    Replies: 2
    Last Post: 14th July 2013, 06:33 AM
  3. play Sound Bug[BETA 26]
    By Nekorai in forum Android Export Module Version 2.0
    Replies: 3
    Last Post: 22nd April 2012, 08:48 PM
  4. Setting a string to the value of a variable
    By mobichan in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 12th February 2009, 06:31 PM
  5. Play sound IMMEDIATELY after other sound finishes
    By LazyCoder in forum Multimedia Fusion 2 - Technical Support
    Replies: 10
    Last Post: 1st September 2007, 12:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •