Created
December 4, 2012 15:06
-
-
Save Choonster/4204952 to your computer and use it in GitHub Desktop.
Revisions
-
Choonster revised this gist
Dec 4, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,6 @@ 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 -
Choonster created this gist
Dec 4, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ 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, -- but passes the result of task directly to the next one instead of explicitly storing the result in a local variable first end