A system for Roblox Luau for easily handling RunService and ContextActionService binds
Provides tools for easy clean-up of groups of binds QoL features for ContextActionService input binds, such as:
- Configurable Input Buffering
- Easy support for held keys
- WrapMethod utility function for adapting classes
I intend to rework this with Roblox's new input system once it's out of beta, primarily to abstract away the Instance-based API Roblox so dearly loves
Create a new group with:
local BindsMod = require(module)
local Group = BindsMod.NewGroup("Group1")Then, you can bind to RenderStepped easily via
Group:Bind{
Service = game:GetService("RunService"), -- must be the instance
Func = function(dt:number) end, -- can pass any function, parameters from the RS event are passed on
Name = "My RS bind!", -- needs name for binding and unbinding
Priority = Enum.RenderPriority.Camera.Value -- has to be a number
}Or, bind to ContextActionService with
Group:Bind{
Service = game:GetService("ContextActionService"),
Func = function(name:string,state:Enum.UserInputState,obj:InputObject) end,
Name = "My CS bind!",
Priority = Enum.ContextActionPriority.Medium.Value
}When binding to CAS extra parameters like
Button:boolean -- whether or not to show the button on mobile
Buffer:number -- input buffering, requires CanActivate to also be passed
CanActivate:(...any)->boolean -- needs a return of true or false, runs every frame that input buffering is active
Held:boolean -- tells the system to listen for held keys, requires CanActivate to be passed
FailCondition:(...any)->() -- if Held is true, fires this if CanActivate returns falseCan be passed to alter how it acts
And, when you are done, just run
Group:Destroy()And everything will be automatically unbound!
Alternatively, do
Group:Unbind(NameOfBind)to unbind individually