Thread Tools Display Modes
04/22/15, 08:15 AM   #1
stAjora
Join Date: Apr 2015
Posts: 20
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...
  Reply With Quote
04/22/15, 08:25 AM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Lua Code:
  1. local value1, value2, value3, value4 = FunctionWichReturnMultipleThings()
  Reply With Quote
04/22/15, 09:07 AM   #3
Halja
 
Halja's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 111
Welcome to lua. 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.
  Reply With Quote
04/22/15, 09:30 AM   #4
stAjora
Join Date: Apr 2015
Posts: 20
Thanks guys, fixed my issue perfectly. I was wondering what the underscore business was about too.
  Reply With Quote
04/22/15, 09:31 AM   #5
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
Originally Posted by Halja View Post
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.
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » function returning multiple strings

Thread Tools
Display Modes

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