Thread Tools Display Modes
09-02-09, 09:22 AM   #1
_Chloe
A Murloc Raider
 
_Chloe's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2008
Posts: 8
Nested ifs and elseifs

So... I can't get this to work out.
All the functions work when called outside of this function.
CBHUF:SMD() just prints a message.
Check 1 fires, Check2 fires, yet Check 3 fails as well at the other 2. Any help would be appreciated as this has been driving me bonkers for about an hour now.
Code:
function CBHUF:PlayerFrameOnEvent(self, event, ...)
	if arg1 == nil then arg1="nil"end
	CBHUF:SMD(event.." arg1="..arg1); --Check 1
	local unit = arg1;
	if (event == "PLAYER_ENTERING_WORLD") then
		CBHUF:PlayerFrameUpdateAll();
	elseif (event == "PLAYER_REGEN_DISABLED" or event == "PLAYER_REGEN_ENABLED") then
		CBHUF:PlayerFrame_UpdateCombatStatus();
	end
	if (unit == "player") then
		CBHUF:SMD("Player Arg Activated! Event:"..event); --Check 2
		if (event == "UNIT_NAME_UPDATE") then
			CBHUF:PlayerFrame_UpdateName();
		elseif (event == "UNIT_LEVEL" or "UNIT_CLASSIFICATION_CHANGED" or event == "PLAYER_LEVEL_UP") then
			CBHUF:PlayerFrame_UpdateLevel();
		elseif (event == "PLAYER_FLAGS_CHANGED") then
			CBHUF:PlayerFrame_UpdateAFK();
			CBHUF:PlayerFrame_UpdatePvP();
			CBHUF:SMD("UPDATING FLAGS!!!");
		elseif (event == "RAID_TARGET_UPDATE") then
			CBHUF:PlayerFrame_UpdateRaidIcon();
		elseif (event == "UNIT_FACTION") then
			CBHUF:PlayerFrame_UpdateFaction();
			CBHUF:PlayerFrame_UpdateReaction();
			CBHUF:PlayerFrame_UpdateLevel();
		elseif (event == "UNIT_PVP_UPDATE") then
			CBHUF:PlayerFrame_UpdatePvP();
		elseif (event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH") then
			CBHUF:PlayerFrame_UpdateHealth();
		elseif (event == "UNIT_DISPLAYPOWER") then
			CBHUF:PlayerFrame_UpdatePowerType();
		elseif (event == "UNIT_MANA" or 
			event == "UNIT_MAXMANA" or 
			event == "UNIT_RAGE" or
			event == "UNIT_MAXRAGE" or
			event == "UNIT_ENERGY" or
			event == "UNIT_MAXENERGY" or
			event == "UNIT_FOCUS" or
			event == "UNIT_MAXFOCUS" or
			event == "UNIT_RUNIC_POWER" or
			event == "UNIT_MAXRUNIC_POWER") then
			CBHUF:SMD("UPDATING POWER!!!!!!!!!!!!!!!!");
			CBHUF:PlayerFrame_UpdateMana();
		elseif (event == "UNIT_THREAT_LIST_UPDATE" or event == "UNIT_THREAT_SITUATION_UPDATE") then
			CBHUF:PlayerFrame_UpdateThreat();
		elseif (event == "PLAYER_UPDATE_RESTING" or event == "PLAYER_XP_UPDATE") then
			CBHUF:PlayerFrame_UpdateXP();
		else
		CBHUF:SMD("NO EVENT MATCHES =("); --Check 3
		end
	end
end

Last edited by _Chloe : 09-02-09 at 09:33 AM.
  Reply With Quote
09-02-09, 09:33 AM   #2
forty2j
A Cobalt Mageweaver
Join Date: May 2007
Posts: 232
I'm not familiar with Lua, but based on my knowledge of numerous other languages, shouldn't

Code:
event == "UNIT_LEVEL" or "UNIT_CLASSIFICATION_CHANGED" or event == "PLAYER_LEVEL_UP"
be

Code:
event == "UNIT_LEVEL" or event == "UNIT_CLASSIFICATION_CHANGED" or event == "PLAYER_LEVEL_UP"
?
  Reply With Quote
09-02-09, 09:58 AM   #3
_Chloe
A Murloc Raider
 
_Chloe's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2008
Posts: 8
damnit... I need to quit trying to code when I'm sleeply. Thanks for the extra set of eyes.
  Reply With Quote
09-02-09, 11:55 AM   #4
forty2j
A Cobalt Mageweaver
Join Date: May 2007
Posts: 232
Originally Posted by _Chloe View Post
damnit... I need to quit trying to code when I'm sleeply. Thanks for the extra set of eyes.
Lol.. not a problem.. I've made similar mistakes while perfectly awake.

Every once in a while, everyone needs a Captain Obvious.
  Reply With Quote
09-02-09, 12:19 PM   #5
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Really, your code could be much cleaner if you made a function for each event (lua table based)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Nested ifs and ifelse


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off