lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I want to reduce the typing of repeating for each RACE, in a array. Contains
location of sound files for each race and sex. How can i optimize
the code below?

Sound file locations seem to repeat with each other containing

local manaSoundList = {
 ["Draenei"] = {
  female = "Sound\\Character\\Draenei\\DraeneiFemale_Err_NoMana03.wav",
  male = "Sound\\Character\\Draenei\\DraeneiMale_Err_NoMana03.wav"
 ["Dwarf"] = {
  female = "Sound\\Character\\Dwarf\\DwarfFemale_Err_NoMana03.wav",
  male = "Sound\\Character\\Dwarf\\DwarfMale_Err_NoMana03.wav"

The below contains a structure to hold all the data from the players
inside the party, if it doesnt exist then we will have to create it to
prevent errors later on

if not healerList[unitID] then
      healerList[unitID] = {}
      healerList[unitID].strikes = 0
      healerList[unitID].name = UnitName(unitID)
      healerList[unitID].unitID = unitID
      healerList[unitID].connection = UnitIsConnected(unitID)
      healerList[unitID].race = select(2,UnitRace(unitID))

local function PlayLowManaSound(unitID)
        if not healerList[unitID] then return end

        local soundFile = nil
        if healerList[unitID].sex == 2 then
                soundFile = manaSoundList[healerList[unitID].race].male
                soundFile = manaSoundList[healerList[unitID].race].female