Howdy ya’ll, this post is to let you all know I released a handy little library recently: ActionContext. It’s an object-oriented way of using Roblox’s ContextActionService and alleviates a good amount of boilerplate code you’d find surrounding BindAction/UnbindAction calls. Rather than re-hash the documentation, I’ll just leave a quick bit of example code here.
local honkAction = {
ActionName = "Honk",
Inputs = { Enum.KeyCode.H, Enum.KeyCode.ButtonY },
Handle = function (userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then
sound:Play()
end
end,
}
local actionContext = ActionContext.new({ honkAction })
-- Entering and leaving the car:
actionContext:Enter()
actionContext:Leave()
How to Get ActionContext into your Roblox Game
- I put together a Roblox model file on the GitHub releases page, which you can drag right into Roblox Studio.
- I also uploaded v1.0.0 to the Roblox Creator Store (note that this may not be the latest at time of writing). Check the releases page for the latest.
- Rojo users can either:
- Clone the repository using something like a git submodule, or for the cool kids…
- It’s also also on Wally:
action-context = "ozzypig/[email protected]"
(Reminder: add this to your project’s wally.toml and then re-runwally install
)
ActionContext is particularly useful for implementing input chords on Roblox, for example Ctrl+C or Ctrl+V, including input triads like Ctrl+Shift+T. It also features some shorthand API for simple button presses.
Hopefully you’ll find using this API a breeze! Feel free to open an issue or contribute code via GitHub.