Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Simple Random Audio Sound

Aeioe

Member

I'm sure this wouldn't be all that difficult to do, but I know basically nothing of RGSS so I'm not sure how I would go about doing this.

I would like to replace the cursor sound with an array of random sounds that every time the cursor moves it chooses a different one from the list.

So for instance as you scroll down through a long list of items, the sound it makes for each item passed is chosen randomly from a list of cursor sounds.

Thanks,
Aeioe

P.S. I'd also like to be able to randomize the pitch if possible.
 

Aeioe

Member

BUMP

Ok so apparently this is more complex than I had previously imagined.

Is it possible to simply make the cursor sound pitch randomize every click?

This way as you scroll through tons of items each movement will always be a little different.

Hoping,
~Aeioe
 
It's fairly easy to do what you want. Take a look at these excerpts from a thunderstorm script that I never released:

Code:
module Thunderclaps
    Thunderclaps = [
      "Audio/SE/181-Thunderclap02.ogg",
      "Audio/SE/182-Thunderclap03.ogg",
      "Audio/SE/183-Thunderclap04.ogg",
      "Audio/SE/184-Thunderclap05.ogg",
      "Audio/SE/185-Thunderclap06.ogg",
      "Audio/SE/186-Thunderclap07.ogg",
      "Audio/SE/187-Thunderclap08.ogg",
      "Audio/SE/188-Thunderclap09.ogg",
      "Audio/SE/189-Thunderclap10.ogg",
      "Audio/SE/190-Thunderclap11.ogg",
      "Audio/SE/191-Thunderclap12.ogg",
      "Audio/SE/192-Thunderclap13.ogg",
      "Audio/SE/193-Thunderclap14.ogg",
      "Audio/SE/194-Thunderclap15.ogg",
      "Audio/SE/195-Thunderclap16.ogg",
      "Audio/SE/196-Thunderclap17.ogg",
      "Audio/SE/197-Thunderclap18.ogg"
    ]
  end

Code:
  def thunderclap
    # Set a random number for the thunderclap audio choice
    thunderclap_number = rand(17)
    # Select thunderclap audio file from the array above
    thunderclap = Thunderclaps::Thunderclaps[thunderclap_number].to_s
    # Set a random number for the pitch of the thunderclap audio
    pitch = rand(61)+70
    # Play the thunderclap audio
    Audio.se_play(thunderclap, 100, pitch)
  end

The first one is what is called an array, and I used it to store the name of every audio file I wanted to play. The second one is what you really need. (Although you should use the array as well) The line "thunderclap_number = rand(17)" sets the variable thunderclap_number to a number from 0 to 16. Since the array has 17 different sounds in it, and an array starts at 0, this is perfect. Next, the line "thunderclap = Thunderclaps::Thunderclaps[thunderclap_number].to_s" sets the variable thunderclap to the name of the sound I want to play, and turns it into a string. Then, I set the pitch to a random number from 70 to 130, and use Audio.se_play to play the sound. I deleted everything that wasn't relevent to what you needed. All you really need to do is taker what I've given to you, change some of the names, turn it into a method in Window_Base, and call that method instead of the default call "$game_system.se_play($data_system.cursor_se)"
 

Aeioe

Member

Thank you very much, this looks precisely like what I'm looking for.

I have inserted both of these into my Window_Base near the bottom and have changed the audio files and random length to look for, however when I try to call them using Window_Base.thunderclap it tells me that the method is undefined for Window_Base:Class.

How do I replace the line
Code:
$game_system.se_play($data_system.cursor_se)
with the desired sound?

Thank you again for the assistance.
~Aeioe
 

Aeioe

Member

I have changed the names now, I always make sure the code is functioning before doing anything else to it. Thank you very much, this has provided a much gentler scroll through items without the incessant repetition.

I appreciate the assistance,
~Aeioe
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top