Effective way of returning table/strings/arrays from function

how can i effectively return strings and tables from a function
without making a messy over engineered code so yeah that’s basically my question

local function soda(kind)
return kind
end

print(soda({“coke”,“koala”,“fanta”,“sprite”}))

–just prints table: and this 0xd49e37add93771f3

i have made it work before but not properly :grinning:

1 Like

I don’t quite understand this question.

0xd49e37add93771f3 is what will appear in the developer console, as it is a a lua table hex code (idk the proper name). In the output window in Roblox Studio, it will display as a table.

If you want to display the table in the developer console or on any UI (which you shouldn’t), you should use JSONEncode, which will turn your table into a JSON string.

If you’re worried that it’s returning 0xd49e37add93771f3 and it won’t work, it will work, the script knows what this means.

1 Like

Since the output got updated, it already prints all values inside the table
image

If for some reason this doesn’t work, then you can wrap the returned table in unpack

what is this 0xd49e37add93771f3 any ways i am a fairly good coder and have no idea what these mean

It’s the table’s memory address

does it have to do with json or something

No - JSON is just what I suggested to make it readable. I didn’t know unpack was a thing lol

anyways thanks for the help i get the idea now

1 Like

unpack and table.unpack are array exclusives, JSONEncode is compatible with both arrays and dictionaries.

1 Like