View Single Post
10/12/14, 06:05 PM   #5
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by circonian View Post
Or maybe it wasn't a type-o.
Does it still work if you do something like:
Lua Code:
  1. return _lItemLink and GetMyLinkItemInfo(_lItemLink) or GetItemInfo(_iBagId, _iSlotId)
... <snip> ...
It fails because of used logical operators (and, or). Logical operators use just the first return value from the function to check if the expression result is true or false. So the function returns just one of values used for evaluation.

If you want to work with multiple return values in logical expression, you will have to store values to the table and then unpack it:
Lua Code:
  1. return unpack(_lItemLink and {GetMyLinkItemInfo(_lItemLink)} or {GetItemInfo(_iBagId, _iSlotId)})

But this is probably better:
Lua Code:
  1. if _lItemLink then
  2.     return GetMyLinkItemInfo(_lItemLink)
  3. else
  4.     return GetItemInfo(_iBagId, _iSlotId)
  5. end
or shorter and even better is:
Lua Code:
  1. if _lItemLink then
  2.     return GetMyLinkItemInfo(_lItemLink)
  3. end
  4. return GetItemInfo(_iBagId, _iSlotId)


Example:
Lua Code:
  1. local function GetMyItemInfo(_iBagId, _iSlotId)
  2.     if type(_iBagId) == "string" then --if the first argument is string, it's itemLink
  3.         return GetMyLinkItemInfo(_iBagId)
  4.     end
  5.     return GetItemInfo(_iBagId, _iSlotId)
  6. end
  7.  
  8. --And then call it:
  9. local sIcon, iStack, iSellPrice, bMeetsUsageRequirement, bLocked, iEquipType, iItemStyle, iItemQuality = GetMyItemInfo(iBagId, iSlotId)
  10. local sIcon, iStack, iSellPrice, bMeetsUsageRequirement, bLocked, iEquipType, iItemStyle, iItemQuality = GetMyItemInfo(lLink)

Last edited by Garkin : 10/12/14 at 07:02 PM.
  Reply With Quote