generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: tuple usage

Previous Thread :: Next Thread 
MagnusAnsel is not online. MagnusAnsel
Joined: 30 May 2017
Total Posts: 9
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 is not online. 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
MagnusAnsel is not online. MagnusAnsel
Joined: 30 May 2017
Total Posts: 9
15 Nov 2017 12:15 PM
thanks unpack() was what i was looking for
Report Abuse
Luckyxero is not online. 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 is not online. 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
MagnusAnsel is not online. MagnusAnsel
Joined: 30 May 2017
Total Posts: 9
15 Nov 2017 01:03 PM
i learned something new thanks a lot
Report Abuse
Galvicand is not online. Galvicand
Joined: 11 Oct 2017
Total Posts: 68
15 Nov 2017 01:09 PM
Nitpick, but ... isn't an operator.
Report Abuse
TaaRt is online. 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 is not online. 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 is online. 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 is online. TaaRt
Joined: 26 Apr 2009
Total Posts: 5039
15 Nov 2017 06:41 PM
*less conventional
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image