Purpose of Ace3's OnDisable() function?
Looking at other people's Ace3-based addons, it seems to be best practice to use the OnDisable() function to undo everything you did in OnEnable(); like hooking functions, registering events etc.
I have been doing the same for my addons but I never really understood why. Because whenever I disable my addon (i.e. untick it in the "AddOn List"), the OK button turns into "Reload UI". So I assume my OnDisable() function is never called at all? Why do I need it then? Furthermore, when I use hooksecurefunc in my OnEnable(), there is not really any way of undoing this in OnDisable(), right? |
Ace expects those 3 functions from its addons.
Most AddOns don't use OnDisable at all but provide it 'just in case'. If it is not going to be used, you can leave it empty. Most AddOns simply silence* themselves for specific configurations/specs/instances/encounters but do not disable completely. *deactivate certain functionalities, unregister certain events etc. If you disable your AddOn via DisableAddOn, it won't be loaded for the following logins/reload. Using an AceAddOns OnDisable, you can deactivate said AddOn's functionalities as defined in the function without a reload (hooks and frames persist). And yes, you can not remove hooks, only with a reload. But if you need to have an option to ignore a hook, you can add a return, eg Lua Code:
see https://www.wowace.com/projects/ace3...etting-started Code:
Standard methods |
Hey thanks! This was pretty enlightening indeed. :-)
So basically I am providing the OnDisable() function for anyone else who wants to silence my Addon in certain situations without having to reload the UI! That's fair enough. Also thanks for the runhook tip! |
You can remove hooks if you use AceHook-3.0.
OnDisable is used if you want to create a "standby" mode for your addon. It isn't truly disabled, as the DisableAddOn API is not called. You would use the function to wipe variables, remove hooks, unregister events, etc, that you don't want to keep in memory or eating CPU cycles during "standby". In your options table, you need to create an option to toggle enable/disable, calling OnEnable and OnDisable respectively. If you leave out the toggle in your options, then your addon will fire OnInitialize and OnEnable as normal, but completely ignore OnDisable. |
I'm not sure if it is in the documentation other than reading the Ace3 code, so here's a tip: if you create the toggle mentioned above in your options table, you can set the load state as per user settings.
Lua Code:
|
@myrroddin:
You missed a bracket ;) @LudiusMaximus As myrroddin states, if you use AceHook, you can unhook your hooks. This is because AceHook itself hooks the function/script and only calls your code when you have told it to do so. AceHook's initial hooks persists though. So it's a question of "do I want to handle hooks myself or should AceHook do it". |
All times are GMT -6. The time now is 01:25 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI