Thread Tools Display Modes
01-21-10, 12:47 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
through symbol?

how do you do number ranges? can i do this

targetlvl = UnitLevel("target")
if targetlvl == 1-9 then
blah blah blah

does that then allow it to respond if the result is 1-9?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-21-10, 12:49 PM   #2
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
That would result in -8 (1 minus 9). What you want is:

Code:
if targetlvl >= 1 and targetlvl <= 9 then
or

Code:
if targetlvl > 0 and targetlvl < 10 then
  Reply With Quote
01-21-10, 12:54 PM   #3
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
has to be 0 if you use 1 it does not do what its supposed to when targeting a lvl 1.

thanks though that is exactly what i needed.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-21-10, 12:56 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
There's no such thing as lvl 0, so you only need

if targetlvl <= 9
__________________
"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
01-21-10, 12:56 PM   #5
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
wait maybe im reading it wrong, when you do the <= or >= does that mean greater/lesser then or equal to?

-- edit: what i mean is... does >= mean "greater then and equal to" ?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 01-21-10 at 12:59 PM.
  Reply With Quote
01-21-10, 01:07 PM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
it does mean that, well the and should be and/or but, akryn was right on both of them. and 0 does have to be used on the 2nd one 10 has to be used on the < side. or when you target a 9 it does not do its thing...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-21-10, 01:18 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Right. Because 10 is not less than 10. But there is no reason why you should bother computing if the level is greater than 0 because there *is* no level 0.

One calculation > two calculations.
__________________
"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
01-21-10, 01:58 PM   #8
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
ah i see so dont use the greater then 1 or 0 at all.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-21-10, 02:06 PM   #9
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
is there a way to do not = to a number? so lets say

or max mana...

if currMana ~= # then
do somthing
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-21-10, 03:33 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Yes. ~= is "not equal to" in Lua.

http://www.lua.org/pil/3.2.html
__________________
"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
01-21-10, 05:28 PM   #11
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Seerah View Post
There's no such thing as lvl 0, so you only need

if targetlvl <= 9
*facepalm me*
well at least that answers how to do it in the future if it comes up again.

Edit: Although, actually, if you target nothing it will error as it is now, so depending on the situation that this is being used for you could still use it like...:
Code:
targetlvl = UnitLevel("target") or 0
if targetlvl > 0 and targetlvl < 10 then
...

Last edited by Akryn : 01-21-10 at 05:31 PM.
  Reply With Quote
01-21-10, 06:54 PM   #12
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Originally Posted by Akryn View Post
*facepalm me*
well at least that answers how to do it in the future if it comes up again.

Edit: Although, actually, if you target nothing it will error as it is now, so depending on the situation that this is being used for you could still use it like...:
Code:
targetlvl = UnitLevel("target") or 0
if targetlvl > 0 and targetlvl < 10 then
...
yea i had to put if unitexsists in it to stop that.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-21-10, 07:00 PM   #13
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Code:
if UnitExists("target") and UnitLevel("target") < 10 then
     --do stuff
end
/edit: or...
Code:
targetlvl = UnitLevel("target")
if targetlvl and targetlvl < 10 then
     --do stuff
end
might be better, since it's only function call.
__________________
"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
01-21-10, 07:25 PM   #14
Recluse
A Cliff Giant
 
Recluse's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 70
You really need to add in the check for '> 0' or '>= 1'.

When you request UnitLevel on a raid boss or an opposing faction player / mob 10 levels above you, UnitLevel returns '-1'. Because of this you'll need to compensate for the possibility.

Code:
if UnitExists("target") then
     local unit_level = UnitLevel("target")
     if unit_level > 0  and unit_level < 10 then
          -- Handle units level 1-9
     end
end
__________________
We'd be together, but only diamonds last forever...
  Reply With Quote
01-21-10, 09:12 PM   #15
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Ahh... Totally forgot about that, since I only use UnitLevel() to check to see if I should gather talents from players.
__________________
"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

WoWInterface » Developer Discussions » Lua/XML Help » through symbol?


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