View Single Post
04/07/14, 04:15 PM   #11
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Originally Posted by Edda View Post
And now for another basic noob question : how do I actually use an event in the fired function ?

I have

Code:
EVENT_MANAGER:RegisterForEvent("MXPV", EVENT_PLAYER_COMBAT_STATE, MXPV.GetCombatState);
Now I want to check if EVENT_PLAYER_COMBAT_STATE is true or false -> documentation says -> (bool inCombat).

I tried

Code:
EVENT_MANAGER:RegisterForEvent("MXPV", EVENT_PLAYER_COMBAT_STATE, MXPV.GetCombatState(event));
MXPV.GetCombatState <-- assigns this function to the event handler
MXPV.GetCombatState(event) <-- calls this function with event as the first argument and assigns the result of that function call to the event handler

You want this:
Lua Code:
  1. function MXPV.GetCombatState(event, inCombat)
  2.      if inCombat then
  3.           --do stuff
  4.      end
  5. end
  6.  
  7. EVENT_MANAGER:RegisterForEvent("MXPV", EVENT_PLAYER_COMBAT_STATE, MXPV.GetCombatState)

or this:
Lua Code:
  1. EVENT_MANAGER:RegisterForEvent("MXPV", EVENT_PLAYER_COMBAT_STATE, function(event, inCombat)
  2.           if inCombat then
  3.                MXPV.GetCombatState(inCombat)
  4.           end
  5.      end)
  Reply With Quote