Thread Tools Display Modes
05-27-08, 03:51 PM   #1
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
Question Don't load if you don't need to

Hi, would just like to know a few things;
  1. How do i not load an addon depending on if the char has a skill or not?
  2. How do restrict text output depending on the skill of the char (and how do i make the background change size depending on it).
Would love to know.

Thanks in advance, Hipjipp
  Reply With Quote
05-27-08, 04:07 PM   #2
Coldfury
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 18
Originally Posted by hipjipp View Post
Hi, would just like to know a few things;
  1. How do i not load an addon depending on if the char has a skill or not?
  2. How do restrict text output depending on the skill of the char (and how do i make the background change size depending on it).
Would love to know.

Thanks in advance, Hipjipp
to load based on something you simply add

if (not playerhasspell("spellname")) then return end

at the top of the file. ull need to find the correct function tho.

exemple to load based on class:
local playerclass = select(2, UnitClass"player")
if(playerclass ~= "HUNTER") then return end
  Reply With Quote
05-27-08, 04:19 PM   #3
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Originally Posted by Coldfury View Post
local playerclass = select(2, UnitClass"player")
if(playerclass ~= "HUNTER") then return end
You are harming yourself if you use select() where you don't need to. A call to select() is slower than simply taking what you need. You would be better off with

local _, playerclass = UnitClass("player")
if (playerclass ~= "HUNTER") then return; end
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
05-27-08, 06:11 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I'm sure it depends on context. Also, if you want the second return, but not the first, third, or fourth, etc.

This is what WoW Programming says in regards to dummy variables (_, playerclass) or using select()

The underscore identifier has become somewhat of a de-facto standard when you need to throw away the result of a function call simply because it's easy to type, and most likely not already in use, but it's considered bad practice.

Instead of using the underscore as a dummy variable, it's better to give each variable a meaningful name, and only use those that are necessary.
Does it make a difference with something this small? I have seen both methods for this particular case be used. In my addon, I have tried both and didn't notice a difference.
__________________
"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
05-27-08, 10:45 PM   #5
zespri
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 2
The underscore thingy is a matter of preference. I personally can't see why it can be considered bad practice. You are basically indicating that the variable has no meaning or use for you. Would it be better to try and give a meaningful name to a meaningless variable? On my opinion, hardly so.
  Reply With Quote
05-28-08, 03:22 AM   #6
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
I would use AddonLoader and place:

Code:
## LoadManagers: AddonLoader
## X-LoadOn-Events: PLAYER_LOGIN
## X-LoadOn-PLAYER_LOGIN: if GetSpellInfo(spellid) then LoadAddon("MyAddon") end
in the toc.

The only thing you need to remember is that the Addon will be loaded after "PLAYER_LOGIN" so you will not be able to use that event.

Last edited by Slakah : 05-28-08 at 03:24 AM.
  Reply With Quote
05-28-08, 01:11 PM   #7
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
i couldnt get the "playerhasspell" thing to work.. as i need my addon to load/not load depending on if i have herbalism or not. I'd prefer not to use addon loader, might be the only way though.. : <

Hope you'll keep posting, i love you guys!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Don't load if you don't need to

Thread Tools
Display Modes

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