Posted by GeodesicDragon on Fri, 08 May 2009 15:57:18
I'm trying to get my addon to play a sound depending on the user's race and gender.
I know that UnitRace and UnitSex are used here, and that UnitSex returns a number (2=male, 3=female).
However, I'm not sure how to get it working.
What I have so far is:
local race=UnitRace("player") local gender_code=UnitSex("player") -- If player is a Tauren Male, do something. if race=="Tauren" and gender_code=="2" then local soundFile = "SOUND HERE" SendAddonMessage("VGC", soundFile, "RAID") end
I don't see anything wrong with it, but then again - I'm not the expert.
Posted by jnwhiteh on Fri, 08 May 2009 16:55:06
UnitGender() returns a number, not a string.
> print("3" == 3) false
Posted by GeodesicDragon on Fri, 08 May 2009 18:55:48
Ah, I see.
Now the problem I've got is my sound not playing.
I'm using the same code you gave me before, except I've changed it (renamed a frame, new message, etc).
if not ReceiveSoundFrameMana then ReceiveSoundFrameMana = CreateFrame("Frame") end local function OnEvent(self, event, prefix, message, channel, sender) if prefix == "VGCM" then print("|cFF00FF00VGComms:|r " ..sender .. "|cFF98CDCD is low on mana!|r") PlaySoundFile(message) end end local frame = ReceiveSoundFrameMana frame:RegisterEvent("CHAT_MSG_ADDON") frame:SetScript("OnEvent", OnEvent) local soundFile = "Sound\\Character\\Tauren\\TaurenMaleVocal\\TaurenMaleOutOfMana01.wav" SendAddonMessage("VGCM", soundFile, "RAID")
Posted by jnwhiteh on Sat, 09 May 2009 08:23:03
I don't see anything specifically wrong with it. You should always add debugging code to help figure out what's going on so you can answer the following questions:
- Is the addon message sent and received?
- Is the event handler being called?
- What specifically is not working, i.e. which line of code is the problem.