Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Register for our event
- --this event has one return, the name of the addon that loaded, causing the event to fire
- --but an event handler (what you are doing right here, assigning a function to an event) will always return what event fired FIRST
- EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_ADD_ON_LOADED, function(event, addon) --this function continues on the next few lines
- if addon == "MyAddon" then --if the addon return matches the name of our addon
- DoSomething() --then do whatever you want when it happens
- end
- end) --this is now the end of the function and the end of the event handler
- --You can also do this by passing a pre-defined event to the event handler, rather than creating an anonymous one
- --When you do this, you can assign multiple events to the same function
- --Let's define our function first --> don't forget that the event code comes first from our event handler!!
- local function MyFunction(event, arg1)
- if event == EVENT_ADD_ON_LOADED then --if it was our addon loading
- DoSomething() --do what you want to at load
- else --if it was our character loading into the world
- d("Hello World!") --do something else
- end
- end
- --now that our function is defined, we can register for our events and pass that function to the event handler
- EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_ADD_ON_LOADED, MyFunction) --the args/returns get passed into our function automatically
- EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_PLAYER_READY, MyFunction)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement