What is Enum.ContextActionPriority

You can write your topic however you want, but you need to answer these questions:

  1. **What do you want to achieve?**The meaning and the purpose of the enums of ContextActionPriority

  2. What is the issue? I searched it on the scripting documentation and says it is used to determine context action order. What does this mean?

  3. What solutions have you tried so far? I tried searching for solutions on the roblox documentation and developer forum.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

I’ve specified all the details above. Any possible solutions will be appreciated. Thank you.

I believe you can use it instead of a number when setting the priorityLevel parameter of the :BindActionAtPriority function, though it’s usually better just to use your own number. You can find more about ContextActionService on the creator documentation hub: ContextActionService | Documentation - Roblox Creator Hub

Low = 1000
Medium = 2000
High = 3000

That’s exactly what I searched but I don’t know what the prioritylevel of a bind action means. Some kind of time after passed the bind action will begin or something?

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.

2 Likes

It means that after the first function was bound the second is expected to bind also?

@Qapandt I’m sorry for the late reply and inconvenience. I forgot to return Enum.ContextActionResult.Pass in the first function (to avoid sinking input).

I hope this clears the confusion up. My original reply is rewritten.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.