Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What exactly is tuple and how is it used?

I'm editing this script (Btw, I'm learning how to script) and I see tuple, but I don't know what it means. Tuple is in line 10 and 11.

local panelID = 3 -- MAKE SURE THIS NUMBER IS NOT THE SAME AS ANY OTHER MACHINE ID ON THE SERVER

local replicatedStorage = game:GetService("ReplicatedStorage")
local remote = replicatedStorage:WaitForChild("RemoteEventSCPPanels")

--Data saving.
local gateMoving = false

remote.OnServerEvent:connect(function(player, ...)
	local tuple = {...}
	if tuple[1] == panelID then
		if tuple[2] == "HCZLockdownOn" then
			if player:GetRankInGroup(3097900) >= 1 then
				if gateMoving == false then
					gateMoving = true
					local task = coroutine.wrap(function()
						while gate1.Position.Z < -555.887 do
							gate1.CFrame = gate1.CFrame + Vector3.new(0, 0, 0.1)
							wait(0.01)
						end
						gateMoving = false
					end)
					task()
					local task = coroutine.wrap(function()
						while gate2.Position.Z > -526.704 do
							gate2.CFrame = gate2.CFrame - Vector3.new(0, 0, 0.1)
							wait(0.01)
						end
						gateMoving = false
					end)
					task()
				end
			end
		elseif tuple[2] == "HCZLockdownOff" then
			if player:GetRankInGroup(3097900) >= 1 then
				if gateMoving == false then
					gateMoving = true
					local task = coroutine.wrap(function()
						while gate1.Position.Z > -564.887 do
							gate1.CFrame = gate1.CFrame - Vector3.new(0, 0, 0.1)
							wait(0.01)
						end
						gateMoving = false
					end)
					task()
					local task = coroutine.wrap(function()
						while gate2.Position.Z < -517.704 do
							gate2.CFrame = gate2.CFrame + Vector3.new(0, 0, 0.1)
							wait(0.01)
						end
						gateMoving = false
					end)
					task()
				end
			end
		end
	end
end)

1 answer

✓ Accepted answer

Hello, Ozorio10_ALT!

In your script, local tuple = {...} is an Array.

Arrays are like an table, and you can save lots of things on it Example:

local Arr = {}
table.insert(Arr, 1) -- This will add 1 to the Array called "Arr"
print(Arr) --Trying to print arrays give something like "table: 2382D96C"

If I print I array it gives the table number so, how to?

You have to use Array Index.

Example:

local Arr = {1, 5, 27, "Scripting", "Helpers", "Website"} -- Don't need to use "table.insert" can set the array elements here
print(Arr[1]) --This code gives "1"
print(Arr[4]) --This code gives "Scripting"

for i=1, #Arr do
	print(Arr[i]) -- This will print "1", "5", "27", "Scripting", "Helpers", "Website" (On Many lines)
end

So, to use Index is ARRAY_NAME[index]

Get the number of elements of an array

Use #ARRAY_NAME.Example:

MyArray = {"An", "Array", "With", "Some", "Elements", "Made", "by", "Leamir"}
print(#MyArray) -- This will print "8"

MyBigArray = {"Arr", 1,27, 98, "Leamir", "ROBLOX", "IS", "REALLY" , "COOL"}
print(#MyBigArray) -- This will print "9"

There are also dictionaryes, but I don't know how to use it :(

Hope this helps =D

Good Luck with your games!!!

1 comment

0

This doesn't really explain what the ... mean

This discussion is preserved as it was. New answers, comments, and votes are closed.