How to make random sounds button?

SmiteSmite TaiwanMember, PRO Posts: 41

Hello everyone

I have a troublesome question that I would like to ask everyone about.

I want to make a button

Each click will make a random different sound (such as the sounds of various animals)

I don't know how to make a button like this

I have seen how to use random numbers on YouTube

But I don’t know how to make a button with random sounds in the simplest way


Ask everyone for advice

grateful

Comments

  • ArmellineArmelline Member, PRO Posts: 5,354

    There are two ways to do this, and which is better depends on the context and how many sound there are.

    Method 1: When the button is pressed, have a random number generated, from 1-X where X is the total number of sounds. Then for each sound, have a rule that says "When random number is 1, play sound 1," "when random numebr is 2, play sound 2" etc. If there are only a handful of sounds, this is the clearest and safest way.


    Method 2: Use the recent update to Tweetsheet to play a sound from an expression. Essentially you'd just name your sounds something like "Sound-1" through "Sound-100" and then you can call a specific sound using an expression. It's waaaay more flexible, but a little more complicated and you can't preview it, it only works in published projects. It's outlined in this thread:

    https://forums.gamesalad.com/discussion/98861/binary-rc-2023-04-21-ad-network-updates-tweet-sheet-for-playsound-and-playvideourl-keyboard-inpu


    If you have fewer than 20 sounds, you're probably safest going with method 1. If you want more flexibility, method 2 works great.

  • SmiteSmite TaiwanMember, PRO Posts: 41

    Thank you very much for your reply

    I think method 1 may be more suitable for my level. I will give it a try.

    thank you again

    Also I have a question about the random function I post another title

Sign In or Register to comment.