Thread Tools Display Modes
02-17-13, 04:43 PM   #1
Nuggs
A Deviate Faerie Dragon
 
Nuggs's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 19
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?
  Reply With Quote
02-17-13, 05:02 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
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
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-17-13, 05:35 PM   #3
Nuggs
A Deviate Faerie Dragon
 
Nuggs's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 19
Originally Posted by Seerah View Post
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

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?

Last edited by Nuggs : 02-17-13 at 05:37 PM. Reason: forgot a question lol..
  Reply With Quote
02-18-13, 07:45 AM   #4
Nuggs
A Deviate Faerie Dragon
 
Nuggs's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 19
No compelling reasons to use the first method, suppose I'll just go with the second.

Last edited by Nuggs : 02-18-13 at 11:11 AM.
  Reply With Quote
02-18-13, 11:52 AM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
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'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-18-13, 10:09 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Disabling addon from within addon.


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off