Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is a tuple?

Asked by 9 years ago

Hello. I recently just found about this thing called Filtering Enabled and omg it looks complicated.

I found some links to Remote Events and stuff but can't find a link about tuples.

Please help asap!

Regards, Nathan.

1 answer

Log in to vote
5
Answered by 9 years ago

A tuple is an ordered list of elements. It means it accepts one or more arguments of any type. Tuple is written as three dots (...) in Lua.

-- param: tuple ...
function foo(...)
  print(...)
end

foo(1,2,3)
> prints '1, 2, 3'
foo("Hi,", " there!")
> prints 'Hi, there!'

------

function bar(...)
  args = {...}
  script.Parent.Name = args[1]
  script.Parent.BrickColor = args[2]
end

bar("Blue Brick", BrickColor.Blue())
> Changes the name to Blue Brick and it's color to Bright blue.

As you see, it's quite up to you how you use it. It's common to assign the tuple in a table in the function to easier handle it throughout the script.

0
Ahah! Thanks! :) Do you have any links aswell? WelpNathan 307 — 9y
0
You can check out https://code.google.com/p/lua-files/wiki/tuple and http://wiki.roblox.com/index.php?title=Tuple, although the firstmentioned can be a bit technical. I don't find the ROBLOX Wiki to cover it too well, sadly Ravenshield 180 — 9y
1
Usually you don't actually need to use (`...`) though, because usually you know exactly how many parameters you are giving it! The remark that it is a tuple is just a technical specification that you *CAN* use as many as you want BlueTaslem 18071 — 9y
Ad

Answer this question