I’ve been learning Python for about a week now and I came across tuples, I was wondering what is the use of them in Roblox(if they exist, I didn’t find much about them on the devhub)
Any examples would be useful!
I’ve been learning Python for about a week now and I came across tuples, I was wondering what is the use of them in Roblox(if they exist, I didn’t find much about them on the devhub)
Any examples would be useful!
Tuples are just array-like tables with a finite known number of indexes (which are often immutable its values can not be changed)
Tuples are not natively supported by Lua as they should be thought of as immuatable . This is not enforced at runtime.
This is a tuple of length three:
-- An array-like table with a length of three.
local tuple = {1, 2, 3};
The following is not a tuple; it is an extremely simplified version that Roblox has stated is idiomatic of its documentation but not of Lua.
Tuples are not defined this way in Lua, any other programming language, or mathematics. For the type theory behind it, refer to here: https://en.wikipedia.org/wiki/Tuple#Type_theory
-- Roblox reference says this is a tuple. It's *really* not.
local elementOne, elementTwo, elementThree = unpack({1, 2, 3});
Ahhh I guess that makes sense, it is a game engine after all.
From what I know, in python you define a tuple like this
Tp = ("one", "two")