WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Disabling addon from within addon. (https://www.wowinterface.com/forums/showthread.php?t=45840)

Nuggs 02-17-13 04:43 PM

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:
  1. if (select(2,UnitClass("player")) == "WARLOCK") or (select(2,UnitClass("player")) == "MONK") then return; end

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?

Seerah 02-17-13 05:02 PM

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:
  1. local _,class == UnitClass("player")
  2. if class == "WARLOCK" or class == "MONK" then
  3.      return
  4. end

Nuggs 02-17-13 05:35 PM

Quote:

Originally Posted by Seerah (Post 273102)
DisableAddOn() is only supposed to be on a per-character basis, so should not affect all of your characters.

That's what I thought until I had it disable it for all my characters(Even the one I wanted it to stay active on. That's when I did a little research and noticed this at the bottom of WoWPedia

Quote:

The first time an addon is disabled (with this function or the user addon panel) it will be disabled for all characters on that realm. Every subsequent time it will enabled/disabled per character.
Which basically got me thinking and thus, spawned this post but thanks for the tip on the function calls. That was something I was thinking about when going over the code and noticed I called those quite a bit when I should just set them to a variable.

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?

Nuggs 02-18-13 07:45 AM

No compelling reasons to use the first method, suppose I'll just go with the second. :)

Seerah 02-18-13 11:52 AM

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. ;)

Phanx 02-18-13 10:09 PM

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")
if class == "WARLOCK" or class == "MONK" then
    return DisableAddOn("ThisAddOn")
end



All times are GMT -6. The time now is 08:09 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI