I was following along Roblox’s documentation about ContextActionService and I reached the section which tells you about :BindActionAtPriority
. And as an example they gave me this code:
local ContextActionService = game:GetService("ContextActionService")
local First_Input_Key = Enum.KeyCode.X
local Second_Input_Key = Enum.KeyCode.Z
local function handleThrow(_, inputState, _)
if inputState ~= Enum.UserInputState.Begin then
return Enum.ContextActionResult.Pass
end
print("Throw")
return Enum.ContextActionResult.Sink
end
local function handlePunch(_, inputState, _)
if inputState ~= Enum.UserInputState.Begin then
return Enum.ContextActionResult.Pass
end
print("Punch")
return Enum.ContextActionResult.Sink
end
ContextActionService:BindAction("HandleThrow", handleThrow, false, First_Input_Key)
ContextActionService:BindAction("HandlePunch", handlePunch, false, First_Input_Key)
ContextActionService:BindActionAtPriority("PrHandleThrow", handleThrow, false, 2, Second_Input_Key)
ContextActionService:BindActionAtPriority("PrHandlePunch", handlePunch, false, 1, Second_Input_Key)
I understood very well what :BindActionAtPriority
was aiming, but the thing that I couldn’t get how it worked was this:
ContextActionService:BindAction("HandleThrow", handleThrow, false, First_Input_Key)
ContextActionService:BindAction("HandlePunch", handlePunch, false, First_Input_Key)
I understood everything until the point where I press the first_input_key where it redirects me to the first function handleThrow()
. Where I would get stuck not understanding the meaning of this if statement:
if inputState ~= Enum.UserInputState.Begin then
Like in every code about ContextActionService in an if statement I never seen this condition. Like inputState NOT TO BE EQUAL(~=) with Enum.UserInputState.Begin
. In this kind of context I have only seen TO BE EQUAL(==). This is the point where I couldn’t understand how this works further.
I would really appreciate if someone could specify what is really happening here.