"end, false, table.unpack(inputs))" what does this line do?

So I was following this smooth camera tutorial on yt by Chrythm and I came across this strange line:

The tutorial:

what does this actually do and how does this work? This is the first time I have ever come across something like this, and the tutorial above doesn’t really explain it.

2 Likes

These are just the parameters after the callback function in the ContextActionService:BindAction() function.

It is structured like this:

ContextActionService:BindAction(actionName: string, functionToBind: Function, createTouchButton: bool, inputTypes)

So basically, the false in your question is referring to the createTouchButton parameter, while the table.unpack(inputs) is the inputTypes parameter.

Learn more about those parameters here:
https://developer.roblox.com/en-us/api-reference/function/ContextActionService/BindAction

1 Like

This is basically just an argument list for a regular function, but formatted to make it easier to read. Let me go through it step by step:

This:

local inputs = {
    [1] = Enum.KeyCode.E;
    [2] = Enum.KeyCode.F;
}

contextActionService:BindAction("ActionName", function()

end, false, table.unpack(inputs)

is the same as this:

local inputs = {
    [1] = Enum.KeyCode.E;
    [2] = Enum.KeyCode.F;
}

contextActionService:BindAction("ActionName", function() end, false, table.unpack(inputs))

However, the top one is much easier to read. The false and table.unpack call are passing parameters to the function, so let me go over that:

local inputs = {
    [1] = Enum.KeyCode.E;
    [2] = Enum.KeyCode.F;
}

contextActionService:BindAction("ActionName", function()

end, 
false, -- This specifies if it should create a touch button for touch controls
table.unpack(inputs)) -- This unpacks a table to use as inputs, typically Keycodes.

When it comes to table.unpack, this:

function printVaradic(...)
    for i,v in pairs({...}) do
        print(v)
    end
end

local t = {
    [1] = Enum.KeyCode.E;
    [2] = Enum.KeyCode.F;
}

printVaradic(table.unpack(t))

is the same as this:

function printVaradic(...)
    for i,v in pairs({...}) do
        print(v)
    end
end

printVaradic(Enum.KeyCode.E, Enum.KeyCode.F)
1 Like