Originally Posted by circonian
Or maybe it wasn't a type-o.
Does it still work if you do something like:
Lua Code:
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:
return unpack(_lItemLink and {GetMyLinkItemInfo(_lItemLink)} or {GetItemInfo(_iBagId, _iSlotId)})
But this is probably better:
Lua Code:
if _lItemLink then
return GetMyLinkItemInfo(_lItemLink)
else
return GetItemInfo(_iBagId, _iSlotId)
end
or shorter and even better is:
Lua Code:
if _lItemLink then
return GetMyLinkItemInfo(_lItemLink)
end
return GetItemInfo(_iBagId, _iSlotId)
Example:
Lua Code:
local function GetMyItemInfo(_iBagId, _iSlotId)
if type(_iBagId) == "string" then --if the first argument is string, it's itemLink
return GetMyLinkItemInfo(_iBagId)
end
return GetItemInfo(_iBagId, _iSlotId)
end
--And then call it:
local sIcon, iStack, iSellPrice, bMeetsUsageRequirement, bLocked, iEquipType, iItemStyle, iItemQuality = GetMyItemInfo(iBagId, iSlotId)
local sIcon, iStack, iSellPrice, bMeetsUsageRequirement, bLocked, iEquipType, iItemStyle, iItemQuality = GetMyItemInfo(lLink)