Disabling addon from within addon.
Hi peoples,
Currently on one of my addons, it's just for warlocks and monks and what I've been doing for the past two and a half years is just disabling the addon when it's loaded if they aren't on one of the classes the addon is for... However, I recently noticed(or maybe I knew before but felt it was acceptable at the time) that the first time the addon disables itself using DisableAddon(), it will do so for every character. This got me thinking, would it be wiser to just make a call something like Lua Code:
at the beginning of the file? I never noticed the pain of DisableAddon until I forgot to disable it on one of my alts and had it get disabled for the characters I didn't want to. I'm no expert with Lua or the WoW API(I don't really even know Lua, I'm just an old UNIX C guy) so it seems like the call I have right there basically stops the addon from loading in the first place without disabling it. Is there a benefit to using DisableAddon() over just issuing a return at the beginning of the script? Would I have to do this for every file included in the addon to prevent it from loading? |
DisableAddOn() is only supposed to be on a per-character basis, so should not affect all of your characters.
But if you decide to go with the second approach still, do it this way instead so you're not making unnecessary function calls. Lua Code:
|
Quote:
Quote:
Anyways, thanks for the info. :) EDIT: If I do go with the second method of just returning at the beginning of the script, would I have to do this for all files which get loaded or only the core file which loads first? |
No compelling reasons to use the first method, suppose I'll just go with the second. :)
|
You would need to do this with all files. They're loaded by the TOC file, not by the Lua file that you put the code in first. ;)
|
You should put the class check in all of your files, but modify one (usually in your main file, or the one that loads first) to disable the addon for characters who don't pass the class check, so you're not wasting time reading all the addon's files and class checking every time you log into that character:
Code:
local _, class == UnitClass("player") |
All times are GMT -6. The time now is 08:09 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI