|
| 15 Nov 2017 12:05 PM |
| can't really find a decent guide on how to use tuples. need to pass multiple arguments and i'm not sure how to use the arguments once they are passed because there are an unknown amount of variables. if anyone could point me to a good tuple guide that would be great. |
|
|
| Report Abuse |
|
|
Galvicand
|
  |
| Joined: 11 Oct 2017 |
| Total Posts: 68 |
|
|
| 15 Nov 2017 12:09 PM |
| Use unpack() if it's from a table and handle it with a variadic function. |
|
|
| Report Abuse |
|
|
|
| 15 Nov 2017 12:15 PM |
| thanks unpack() was what i was looking for |
|
|
| Report Abuse |
|
|
Luckyxero
|
  |
| Joined: 26 Feb 2014 |
| Total Posts: 505 |
|
|
| 15 Nov 2017 12:31 PM |
| If the function returns multiple values and you want to use all those values in an arguments at once, you must use the "..." operator. -- Example function ReturnMultiple() return ## ## ## ## ## ## # end function Calculate(...) local Result = 0 for i, v in pairs{...} do Result = Result + v end return Result end local Value = Calculate(ReturnMultiple()) print(Value) |
|
|
| Report Abuse |
|
|
Luckyxero
|
  |
| Joined: 26 Feb 2014 |
| Total Posts: 505 |
|
|
| 15 Nov 2017 12:33 PM |
function ReturnMultiple() return 1, 2, 3 -- and so on end
function Calculate(...) local Result = 0 for i, v in pairs{...} do Result = Result + v end return Result end
local Value = Calculate(ReturnMultiple()) print(Value)
|
|
|
| Report Abuse |
|
|
|
| 15 Nov 2017 01:03 PM |
| i learned something new thanks a lot |
|
|
| Report Abuse |
|
|
Galvicand
|
  |
| Joined: 11 Oct 2017 |
| Total Posts: 68 |
|
|
| 15 Nov 2017 01:09 PM |
| Nitpick, but ... isn't an operator. |
|
|
| Report Abuse |
|
|
TaaRt
|
  |
| Joined: 26 Apr 2009 |
| Total Posts: 5039 |
|
|
| 15 Nov 2017 01:53 PM |
The string concatenation operator in Lua is denoted by two dots ('..')
From the official Lua docs |
|
|
| Report Abuse |
|
|
Galvicand
|
  |
| Joined: 11 Oct 2017 |
| Total Posts: 68 |
|
|
| 15 Nov 2017 06:39 PM |
i'm going to give you the benefit of the doubt and assume you didn't read the thread and misread the number of periods there
because that was irrelevant |
|
|
| Report Abuse |
|
|
TaaRt
|
  |
| Joined: 26 Apr 2009 |
| Total Posts: 5039 |
|
|
| 15 Nov 2017 06:40 PM |
| Ah I see, I figured it'd not be unlikely people don't recognise the more conventional operators but you're right, 3 dots is no operator |
|
|
| Report Abuse |
|
|
TaaRt
|
  |
| Joined: 26 Apr 2009 |
| Total Posts: 5039 |
|
| |
|
|
| 15 Nov 2017 06:43 PM |
They do call it the 'Ellipsis Operator', but of course that doesn't make it an operator.
|
|
|
| Report Abuse |
|
|
TaaRt
|
  |
| Joined: 26 Apr 2009 |
| Total Posts: 5039 |
|
|
| 15 Nov 2017 06:52 PM |
| Wew apparently ... can be used as a shorthand template in C/C++, that's pretty awesome |
|
|
| Report Abuse |
|
|