Is it possible to get a random sound when I pick up an object? And how can I do it?
Is it possible to get a random sound when I pick up an object? And how can I do it?




One way of doing it is to use a random value for a counter or alterable value. Then have an event for each different value of the counter to play a different sample Eg:
Play picks up an object > Set counter to random(3)+1
If counter = 1
Then
Play sample 1, set counter to -1
If counter = 2
Then
Play sample 2, set counter to -1
If counter = 3
Then
Play sample 3, set counter to -1
Thank you!
I can also set the event "Only one action when event loop" instead of set counter to -1![]()
This is one of the areas where I'd really love to see MMF2 improve a bit; playing samples or creating objects using expressions.
Nope, that won't work; you won't hear a sound if the same random number is generated again.I can also set the event "Only one action when event loop" instead of set counter to -1 \:\)
If more sounds are involved I'd personally set it up like this instead (it's worth having an extra condition to save an extra action per each "play sample" event):Play picks up an object > Set counter to random(3)+1
If counter = 1
Then
Play sample 1, set counter to -1
If counter = 2
Then
Play sample 2, set counter to -1
If counter = 3
Then
Play sample 3, set counter to -1
Play picks up an object > Set counter to random(4)+1
If counter = 1 then play sample 1
If counter = 2 then play sample 2
If counter = 3 then play sample 3
If counter = 4 then play sample 4
If counter > 0 then set counter to 0
Nope, that won't work; you won't hear a sound if the same random number is generated again.I can also set the event "Only one action when event loop" instead of set counter to -1 \:\)
Ok. Try to do this.
+Start of frame
-Set counter to Random(3)+1
+Counter=1
+Only one action when event loop
-Play sample 1
+Counter=2
+Only one action when event loop
-Play sample 2
+Counter=3
+Only one action when event loop
-Play sample 3
This will for example play a random song at the start of frame.
And it's working.![]()
But it still won't work correctly if you trigger it more than once...
The emphasis in what I said was on the second part ("...if the same random number is generated again"). If you perform your events at start of frame, of course it will work. However, try to do it once every second or whenever you press space bar, and hear the silence the second time the same random number is generated.
Nifflas: I don't think I need to try it, because I know that it won't work.And both of you have right.
I have had some problems with the sound when I pick up for example a coin. Or the sound when I'm falling.
I fixed it with "Only one action when event loop" The problem is when I have a random sound on that coin or when I'm falling. Then I can't use "Only one action when event loop". I haven't tried this with random sound on an object I pick up yet. I will come back later if it's working or not working.