|
| 22 May 2016 10:18 PM |
Is it possible to return two things in a function... and, honestly, how do I use returns? I've never really figured it out. Would it be something like...
function Test() return "Hello", "Hello2" end
Test() print(Test[1])
... or something like this?
|
|
|
| Report Abuse |
|
|
|
| 22 May 2016 10:23 PM |
Nevermind, I found out that this works...
function test(String1) return {String1, "String2"} end
x = test("String1") print(x[1]) print(x[2])
#code function brag() print("R$1,712") end |
|
|
| Report Abuse |
|
|
|
| 22 May 2016 10:25 PM |
This also works.
function Test() return "String1", "String2" end
local A, B = Test() print(A) print(B)
|
|
|
| Report Abuse |
|
|
|
| 22 May 2016 10:25 PM |
Hmm, I think I might do it my way, but that is a good way to keep in mind.
#code function brag() print("R$1,712") end |
|
|
| Report Abuse |
|
|
|
| 22 May 2016 10:27 PM |
It kind of depends on the need. They can also be interchanged very easily.
If you use the function I declared above, you can turn it into a table: local AB = {Test()} print(AB[1]) print(AB[2])
Using your function, you can turn it into a tuple: local A, B = unpack(Test()) print(A) print(B)
|
|
|
| Report Abuse |
|
|