API:Class/ContextActionService

Client only:This service is client-side only! You should use a LocalScript instead of a Script when using it.
Filtered-inheritance mode: While this class technically inherits all Instance class members, some (if not all) have been hidden because they serve no purpose for this object.
Service: This class is a service. It is a top-level singleton which can be obtained with the GetService method.

Clickdetector icon.pngContextActionService : Object Icon.pngInstance

A service to bind contextual actions to user inputs, ie actions that should only be enabled for certain periods of time. Examples include reloading a weapon whilst holding it, locking a door whilst standing near it, etc. The action should be unbound when the context is no longer appropriate

Especially useful for supporting keyboard-less users, where onscreen touch buttons can be used in place of keyboard events. This service allows the position, text, and image of these buttons to be configured. These buttons show and hide when actions are enabled and disabled.

Functions

FunctionsmemberhiddenFunctions [toggle]

voidBindAction ( string actionName, function functionToBind, bool createTouchButton, Tuple inputTypes )

Binds function to fire when specified inputTypes occur.

|RMD member="API:Class/ContextActionService/BindAction"|Binds function to fire when specified inputTypes occur.|/RMD|
voidBindActionAtPriority ( string actionName, function<ContextActionResult>(string, UserInputState, InputObject) functionToBind, bool createTouchButton, int priorityLevel, Tuple<string, KeyCode, UserInputType, PlayerActions> inputTypes )

Binds function to fire when specified inputTypes occur. Allows the priority of the bound action to be specified.

|RMD member="API:Class/ContextActionService/BindActionAtPriority"|Binds function to fire when specified inputTypes occur. Allows the priority of the bound action to be specified.|/RMD|
voidBindActivate ( UserInputType userInputTypeForActivation, KeyCode keyCodeForActivation = Unknown )

Specifies the KeyCode that can be used with a UserInputType to activate a Tool, or a HopperBin.

|RMD member="API:Class/ContextActionService/BindActivate"|Specifies the KeyCode that can be used with a UserInputType to activate a Tool, or a HopperBin.|/RMD|
dictionary<dictionary<Variant>>GetAllBoundActionInfo ( )

Returns a table with all bound action info.

|RMD member="API:Class/ContextActionService/GetAllBoundActionInfo"|Returns a table with all bound action info.|/RMD|
dictionary<Variant>GetBoundActionInfo ( string actionName )

Returns a table with info regarding the function bound with actionName.

|RMD member="API:Class/ContextActionService/GetBoundActionInfo"|Returns a table with info regarding the function bound with actionName.|/RMD|
stringGetCurrentLocalToolIcon ( )

Returns the TextureId of a tool currently equipped by the Player, if one is equipped.

|RMD member="API:Class/ContextActionService/GetCurrentLocalToolIcon"|Returns the TextureId of a tool currently equipped by the Player, if one is equipped.|/RMD|
voidSetDescription ( string actionName, string description )

If actionName key contains a bound action, then description is set as the description of the bound action.

|RMD member="API:Class/ContextActionService/SetDescription"|If actionName key contains a bound action, then description is set as the description of the bound action.|/RMD|
voidSetImage ( string actionName, string image )

If actionName key contains a bound action, then image is set as the image of the touch button.

|RMD member="API:Class/ContextActionService/SetImage"|If actionName key contains a bound action, then image is set as the image of the touch button.|/RMD|
voidSetPosition ( string actionName, UDim2 position )

If actionName key contains a bound action, then position is set as the position of the touch button.

|RMD member="API:Class/ContextActionService/SetPosition"|If actionName key contains a bound action, then position is set as the position of the touch button.|/RMD|
voidSetTitle ( string actionName, string title )

If actionName key contains a bound action, then title is set as the title of the touch button.

|RMD member="API:Class/ContextActionService/SetTitle"|If actionName key contains a bound action, then title is set as the title of the touch button.|/RMD|
voidUnbindAction ( string actionName )

If actionName key contains a bound action, removes function from being called by all input that it was bound by.

|RMD member="API:Class/ContextActionService/UnbindAction"|If actionName key contains a bound action, removes function from being called by all input that it was bound by.|/RMD|
voidUnbindActivate ( UserInputType userInputTypeForActivation, KeyCode keyCodeForActivation = Unknown )

Undos the specification of a KeyCode that can be used with a UserInputType to activate a Tool, or a HopperBin, if it was set earlier using BindActivate.

|RMD member="API:Class/ContextActionService/UnbindActivate"|Undos the specification of a KeyCode that can be used with a UserInputType to activate a Tool, or a HopperBin, if it was set earlier using BindActivate.|/RMD|
voidUnbindAllActions ( )

Removes all functions bound. No actionNames will remain. All touch buttons will be removed.

|RMD member="API:Class/ContextActionService/UnbindAllActions"|Removes all functions bound. No actionNames will remain. All touch buttons will be removed.|/RMD|
voidBindActionToInputTypes ( string actionName, function functionToBind, bool createTouchButton, Tuple inputTypes ) [deprecated]

Deprecated. Do not use.

|RMD member="API:Class/ContextActionService/BindActionToInputTypes"|Deprecated. Do not use.|/RMD|
BindAction ( string actionName, function functionToBind, bool createTouchButton, Tuple inputTypes )
Binds function to fire when specified inputTypes occur.
BindActionAtPriority ( string actionName, function<ContextActionResult>(string, UserInputState, InputObject) functionToBind, bool createTouchButton, int priorityLevel, Tuple<string, KeyCode, UserInputType, PlayerActions> inputTypes )
Binds function to fire when specified inputTypes occur. Allows the priority of the bound action to be specified.
BindActivate ( UserInputType userInputTypeForActivation, KeyCode keyCodeForActivation = Unknown )
Specifies the KeyCode that can be used with a UserInputType to activate a Tool, or a HopperBin.
Returns a table with all bound action info.
GetBoundActionInfo ( string actionName )
Returns a table with info regarding the function bound with actionName.
Returns the TextureId of a tool currently equipped by the Player, if one is equipped.
SetDescription ( string actionName, string description )
If actionName key contains a bound action, then description is set as the description of the bound action.
SetImage ( string actionName, string image )
If actionName key contains a bound action, then image is set as the image of the touch button.
SetPosition ( string actionName, UDim2 position )
If actionName key contains a bound action, then position is set as the position of the touch button.
SetTitle ( string actionName, string title )
If actionName key contains a bound action, then title is set as the title of the touch button.
UnbindAction ( string actionName )
If actionName key contains a bound action, removes function from being called by all input that it was bound by.
UnbindActivate ( UserInputType userInputTypeForActivation, KeyCode keyCodeForActivation = Unknown )
Undos the specification of a KeyCode that can be used with a UserInputType to activate a Tool, or a HopperBin, if it was set earlier using BindActivate.
Removes all functions bound. No actionNames will remain. All touch buttons will be removed.
BindActionToInputTypes ( string actionName, function functionToBind, bool createTouchButton, Tuple inputTypes ) [deprecated]
Deprecated. Do not use.

YieldFunctions

YieldFunctions [toggle]

Ref<ImageButton>GetButton ( string actionName )

If actionName key contains a bound action, then this will return the touch button (if was created). Returns nil if a touch button was not created.

|RMD member="API:Class/ContextActionService/GetButton"|If actionName key contains a bound action, then this will return the touch button (if was created). Returns nil if a touch button was not created.|/RMD|
GetButton ( string actionName )
If actionName key contains a bound action, then this will return the touch button (if was created). Returns nil if a touch button was not created.

Events

Events [toggle]

LocalToolEquipped ( Tool toolEquipped )

Fires when the current player equips a Tool.

|RMD member="API:Class/ContextActionService/LocalToolEquipped"|Fires when the current player equips a Tool.|/RMD|
LocalToolUnequipped ( Tool toolUnequipped )

Fires when the current player unequips a Tool.

|RMD member="API:Class/ContextActionService/LocalToolUnequipped"|Fires when the current player unequips a Tool.|/RMD|
LocalToolEquipped ( Tool toolEquipped )
Fires when the current player equips a Tool.
LocalToolUnequipped ( Tool toolUnequipped )
Fires when the current player unequips a Tool.

|RMD member="API:Class/ContextActionService"|A service to bind contextual actions to user inputs, ie actions that should only be enabled for certain periods of time. Examples include reloading a weapon whilst holding it, locking a door whilst standing near it, etc. The action should be unbound when the context is no longer appropriate Especially useful for supporting keyboard-less users, where onscreen touch buttons can be used in place of keyboard events. This service allows the position, text, and image of these buttons to be configured. These buttons show and hide when actions are enabled and disabled. |/RMD|



See also