CORRECTED
In the original version of this post, I forgot to mention that the first bound action SINKS INPUT by default.
Furthermore, there is a confusing error in the official documentation. I’ll write a report.
As Otter_Night already mentioned, priority simply indicates which bound function should be prioritized in the order multiple functions are ran when they’re bound to the same input.
[Function 1] --> higher priority, runs first
[Function 2] --> lower priority, runs second
The higher the number, the higher the priority.
Enum.ContextActionPriority.High.Value --> 3000
Enum.ContextActionPriority.Low.Value --> 1000
Enum.ContextActionPriority
is a data type, and Value
is the number. There are exactly 3001 possible places, including 0.
:BindAction()
:BindAction()
doesn’t specify the order, and how it works is, the action that is bound later also has higher priority.
local CAS = game:GetService("ContextActionService")
local function FirstInQueue(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print(actionName)
end
return Enum.ContextActionResult.Pass
end
local function SecondInQueue(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print(actionName)
end
return Enum.ContextActionResult.Sink
end
CAS:BindAction("Action2", SecondInQueue, false, Enum.KeyCode.T) --> bound first; lower pririty
CAS:BindAction("Action1", FirstInQueue, false, Enum.KeyCode.T) --> bound second; higher priority
OUTPUT
Action1
Action2
:BindActionAtPriority
The advantage is one additional argument, that is priority. No matter in which order the two actions with the same input are bound, the one with higher priority is going to be called earlier.
local CAS = game:GetService("ContextActionService")
local function FirstInQueue(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print(actionName)
end
return Enum.ContextActionResult.Pass
end
local function SecondInQueue(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print(actionName)
end
return Enum.ContextActionResult.Sink
end
CAS:BindActionAtPriority("Action1", FirstInQueue, false, 2, Enum.KeyCode.T)
CAS:BindActionAtPriority("Action2", SecondInQueue, false, 1, Enum.KeyCode.T)
Action1
defined earlier? Defined later? Doesn’t matter.