ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   AddOn Help/Support (https://www.esoui.com/forums/forumdisplay.php?f=164)
-   -   function returning multiple strings (https://www.esoui.com/forums/showthread.php?t=4630)

stAjora 04/22/15 08:15 AM

function returning multiple strings
 
I'm using the GetGuildMemberInfo() function and it returns multiple strings:
Returns: string name, string note, integer rankIndex, integer playerStatus, integer secsSinceLogoff

I can't figure out how to access individual strings because it doesn't seem like these are returned in an array.

local xx = GetGuildMemberInfo(1 ,1)
d(xx[1]) -- should return the guild members name, but it's not an array...

Ayantir 04/22/15 08:25 AM

Lua Code:
  1. local value1, value2, value3, value4 = FunctionWichReturnMultipleThings()

Halja 04/22/15 09:07 AM

Welcome to lua. :D Ayantir showed how to catch them. Note the local is important to avoid Global leaking. Say you don't care about the fourth return. Then this can be done.
Lua Code:
  1. local value1, value2, value3 = FunctionWichReturnMultipleThings()
The value four is just disgraded. Sometimes you will see people ignoring with the underscore.
Lua Code:
  1. local value1, _, value3, _, value4 = FunctionWichReturnMultipleThings()

You could try 'unpack' the returns just to the debug message. It should be work since it is string and integers.
Lua Code:
  1. d(unpack(GetGuildMemberInfo(1 ,1)))
That is one way to find the number of returns if you are not sure.

stAjora 04/22/15 09:30 AM

Thanks guys, fixed my issue perfectly. I was wondering what the underscore business was about too.

Sasky 04/22/15 09:31 AM

Quote:

Originally Posted by Halja (Post 20777)
Lua Code:
  1. d(unpack(GetGuildMemberInfo(1 ,1)))
That is one way to find the number of returns if you are not sure.

You have unpack backwards there.

You can turn it into an array with:
Lua Code:
  1. local memberInfo = {GetGuildMemberInfo(1 ,1)}
which can then be accessed as you were originally expecting, stAjora.

Unpack is to go the other way if you need to get from an array to list of values:
Lua Code:
  1. local args={1,1}
  2. local a,b,c,d = GetGuildMemberInfo(unpack(args))

See http://www.lua.org/pil/5.1.html for more details about multiple return values and unpack.


All times are GMT -6. The time now is 11:32 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI