Random Sounds

Lu_merlinLu_merlin Member Posts: 45
edited November -1 in Working with GS (Mac)
Hello i would like it that when you press a button the actor would "play" a sound. I don't want it to be the same sound over and over again so i would need to be able to play a random number of sounds.

Maybe there is an easy way!

Please let me know.

-Lu_merlin

Comments

  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Hi. You would need to create a game attribute called something like sound

    You then would need a rule on your button that does;

    When touch is pressed
    Change attribute game.sound to Random (1,X) - X being the number of sunds you have.

    Then another rule that says;

    If attribute game.sound = 1
    Play sound 1
    If attribute game.sound = 2
    Play sound 2

    etc etc
  • part12studiospart12studios Member Posts: 620
    Hi there, I know this is an old post but a current issue i'm dealing with. overall this suggestion nails the problem on the head.. except i've isolated one situation:

    when doing the above thread (i made a game.random integer) the int was an assumption..

    i put out text display to show what the random outputs would be and before i did this i would occasionally get missed clicks.. what i've realized with the text output is any time the random number is repeated, then the audio won't play.. example of a random(1,5) which is what i have:

    1-play
    4-play
    3-play
    3-no play
    4-play
    2-play
    2-no play
    etc..

    does anyone have any suggestions

    Thanks!
    Caleb
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi Caleb, unchecking Run to Completion should solve it.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • part12studiospart12studios Member Posts: 620
    Hi gyro,

    Thanks for replying, I had tried that and checked or unchecked i seem to experience the exact same behavior

    Thanks!
    Caleb
  • part12studiospart12studios Member Posts: 620
    ok i found a fix for anyone who might see this again.. inside of each of the rules.. i created an additional change attribute that set the game.random_sound value back to 0... which is always out side the random(1,x) range..

    and if you run into "clipping audio trouble" you actually want "Run to completion" which seemed to work great without having to employ a timer..
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Glad you got it solved. I'm guessing your sound files are really short, otherwise if they were longer, and you didn't want the sound to be interrupted if your button was pressed fast with two duplicate sounds one after the other happening, you wouldn't get the second sound playing immediately.

    But if you did want to solve that potential problem with longer sounds by keeping Run to Completion checked, you could set up as many booleans as you have sounds, and each time a particular sound is pressed toggle between true and false.

    By making a set of duplicate sounds, put - for each different sound - when bool. att. SoundX is false, play the first version, then change attribute to true; when SoundX is true, play the second version, change att. to false. this way, if there were two longer sound files the same, one after the other, they'd finish playing, overlap as you would want, and avoid any backlog.

    Just an idea if your going to be using longer sounds...

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • part12studiospart12studios Member Posts: 620
    ah ok i see what you mean and yea my sounds were just grunts / footsteps.. roughly 1 second each..

    that's a great suggestion about the bools too. I like that. thanks! :)
Sign In or Register to comment.