Thread Tools Display Modes
08-25-13, 02:35 PM   #1
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
[Question] if, or, then statement

I am modifying nMinimap's tab code to only show AddOns above 50 memory when no modifer is held down, and AddOns below 50 memory when CTRL is held down. I called the 50 memory 'memoryThreshold' so I can easily configure it at the top.

Code:
if (IsAddOnLoaded(i)) and GetAddOnMemoryUsage(i)>memoryThreshold or (IsControlKeyDown()) and GetAddOnMemoryUsage(i)<memoryThreshold and IsAddOnLoaded(i) then
Currently what this does is it shows AddOns above the threshold when no modifier is held down (as intended), but when I hold CTRL it shows AddOns both above and below the threshold, instead of just below.
  Reply With Quote
08-25-13, 02:47 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You need to group the conditions you want evaluated together using parentheses.
Lua Code:
  1. if IsAddOnLoaded(i)
  2. and (IsControlKeyDown() and GetAddOnMemoryUsage(i) < memoryThreshold
  3. or GetAddOnMemoryUsage(i) > memoryThreshold) then
Do not put parentheses around single functions because that adds some overhead to the operation. Doing (IsAddonLoaded(i)) is actually slower than just IsAddonLoaded(i).

Last edited by semlar : 08-25-13 at 02:53 PM.
  Reply With Quote
08-25-13, 02:51 PM   #3
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
Ahh of course, that makes sense. Thank you, Semlar

Edit: Bummer, it does not work or else I typed it in wrong.
Here's the whole function: http://pastebin.com/0K59Gp5C

Last edited by laukond : 08-25-13 at 02:56 PM.
  Reply With Quote
08-25-13, 03:03 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Instead of just having (IsControlKeyDown() and GetAddOnMemoryUsage(i) < memoryThreshold) grouped it needs to be all of (IsControlKeyDown() and GetAddOnMemoryUsage(i) < memoryThreshold or GetAddOnMemoryUsage(i) > memoryThreshold).

If that doesn't work try this, which is more verbose but I don't think it should be necessary
Lua Code:
  1. if IsAddOnLoaded(i)
  2. and ((IsControlKeyDown() and GetAddOnMemoryUsage(i) < memoryThreshold)
  3. or (not IsControlKeyDown() and GetAddOnMemoryUsage(i) > memoryThreshold)) then
  Reply With Quote
08-25-13, 03:09 PM   #5
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
The last part worked for me.
Thanks.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » [Question] if, or, then statement


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