Thread Tools Display Modes
02-21-13, 11:45 PM   #1
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Issue with select() and IsInInstance()

Is there a reason why:

Lua Code:
  1. local inInstance, instanceType = IsInInstance()

returns BOOLEAN, TYPE

and

Lua Code:
  1. select(1, IsInInstance())

returns BOOLEAN TYPE together? Select(2, *) returns JUST the type, so why can't I return just the boolean?
  Reply With Quote
02-21-13, 11:47 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Because select returns all values after the one specified, as well.

If you just want the first value, just do "local inInstance = IsInInstance()".

There is a way to force it to only return one value, and that's by wrapping it in parentheses, but there's no reason to do that here.
  Reply With Quote
02-21-13, 11:49 PM   #3
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Nevermind, thank you.

Zzzzz -.-
  Reply With Quote
04-12-13, 10:27 AM   #4
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by semlar View Post
There is a way to force it to only return one value, and that's by wrapping it in parentheses, but there's no reason to do that here.
I would be instrested with this force only the selected value. Is this some kinda new bug, i think it only returned the actually selected parameter.
  Reply With Quote
04-12-13, 01:13 PM   #5
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Normal lua behavior, use (IsInInstance()) to only get the first.
  Reply With Quote
04-12-13, 01:17 PM   #6
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by p3lim View Post
Normal lua behavior, use (IsInInstance()) to only get the first.
Well obv. i want to use it on a different stuff like "print(select(2, GetWorldStateUIInfo(3)))" prints every parameter from the second one.
  Reply With Quote
04-12-13, 01:33 PM   #7
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
You need to wrap your function in parenthesis like so:

print((select(2, GetWorldStateUIInfo(3))))

If that doesn't work, try:

local _, state = GetWorldStateUIInfo(3)

Edit: Fixed a mistake.

Last edited by Clamsoda : 04-12-13 at 02:05 PM.
  Reply With Quote
04-12-13, 01:46 PM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Originally Posted by Resike View Post
I would be instrested with this force only the selected value. Is this some kinda new bug, i think it only returned the actually selected parameter.
It's not a bug, it's even documented as doing such. See Select() under Official Lua 5.1 Manual §5.1.



Originally Posted by Resike View Post
Well obv. i want to use it on a different stuff like "print(select(2, GetWorldStateUIInfo(3)))" prints every parameter from the second one.
As mentioned earlier, encase the Select() call in parenthesis to only use the first return.
(The post by Clamsoda put them around the wrong function.)
Code:
print((select(2, GetWorldStateUIInfo(3))))
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-12-13 at 01:48 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Issue with select() and IsInInstance()


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