Created
December 4, 2012 15:06
-
-
Save Choonster/4204952 to your computer and use it in GitHub Desktop.
A WoW script that provides two functions to play a random sound from a list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local soundFiles = { -- These are example files only | |
"Sound\\Creature\\SomeCreature\\SomeCreature_Aggro01.ogg", | |
"Sound\\Creature\\OtherThing\\OtherThing_Greeting01.ogg" | |
"Interface\\AddOns\\MyAddOn\\Sounds\\levelup1.ogg" | |
} | |
local numSounds = #soundFiles -- Get the number of entries in the soundFiles table | |
local function PlayRandomSound() | |
local index = random(1, numSounds) -- Generate a random number between 1 and numSounds to use as an index. random is an alias of the math.random function | |
local path = soundFiles[index] -- Get the path at the generated index | |
PlaySoundFile(path) -- Play the sound file | |
end | |
local function PlayRandomSoundAbbrev() -- This is a shorter version of the function above that does the exact same thing | |
PlaySoundFile(soundFiles[random(1, numSounds)]) | |
-- The above line performs each "task" in the same order as the first function (function call, table lookup, function call), | |
-- but passes the result of the "task" directly to the next one instead of explicitly storing the result in a local variable first | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment