PageSourceSearch

https://docs.ozzypig.com/ActionContext/main/assets/js/0e89244e.11c82084.js

js ozzypig.com collected 2026-10-04 12:46:04 UTC 11,459 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[735],{92180:n=>{n.exports=JSON.parse('{"functions":[{"name":"fromChildren","desc":"Create a new `ActionContext` with actions from ModuleScripts within\\na given container instance. These ModuleScripts are expected\\nto return tables which are ActionHandlers.\\n\\nModules are required in ascending order of the RequirePriority\\nattribute, if defined, then followed by unset priority modules\\nin an undefined order.\\n\\nAfter requiring, the array of actions is reversed, causing the\\nhigher priority modules\' actions to be bound after the\\nlower priority modules\' actions. This means that their action\\nhandlers take priority if they share inputs.","params":[{"name":"instance","desc":"","lua_type":"Instance"}],"returns":[{"desc":"","lua_type":"ActionContext\\n"}],"function_type":"static","source":{"line":203,"path":"src/init.luau"}},{"name":"action","desc":"Create an action handler of a given name which runs a callback\\non a particular input and desired user input state. The handler sinks\\nall other inputs. Useful for one-shot key commands.\\n\\n```lua\\nActionContext.new({\\n\\tActionContext.action(\\"Honk\\", Enum.UserInputState.Begin, { Enum.KeyCode.H }, function () sound:Play() end)\\n}):Enter()\\n```","params":[{"name":"actionName","desc":"","lua_type":"string"},{"name":"desiredUserInputState","desc":"","lua_type":"Enum.UserInputState"},{"name":"inputs","desc":"","lua_type":"{ UserInput }"},{"name":"callback","desc":"","lua_type":"HandleInputObjectCallback\\n"}],"returns":[{"desc":"","lua_type":"ActionHandler\\n"}],"function_type":"static","source":{"line":221,"path":"src/init.luau"}},{"name":"actionBegin","desc":"A shortcut for [ActionContext.action] with Enum.UserInputState.Begin\\n\\n```lua\\nActionContext.new({\\n\\tActionContext.actionBegin(\\"Honk\\", { Enum.KeyCode.H }, function () sound:Play() end)\\n}):Enter()\\n```\\n\\nWarning: Don\'t combine with ActionContext.actionEnd, as the underlying\\nActionContext.action sinks all other input states. Even if both actions\\nused different names for the same input (also not recommended),\\nthe latter action will take priority and sink inputs before they\\nreach the formerly bound action. If you need to handle multiple\\nuser input states, use ActionContext.action once i.e. bind only one action.","params":[{"name":"actionName","desc":"","lua_type":"string"},{"name":"inputs","desc":"","lua_type":"{ UserInput }"},{"name":"callback","desc":"","lua_type":"HandleInputObjectCallback\\n"}],"returns":[{"desc":"","lua_type":"ActionHandler\\n"}],"function_type":"static","source":{"line":255,"path":"src/init.luau"}},{"name":"actionEnd","desc":"Same as [ActionContext.actionBegin], except for Enum.UserInputState.End","params":[{"name":"actionName","desc":"","lua_type":"string"},{"name":"inputs","desc":"","lua_type":"{ UserInput }"},{"name":"callback","desc":"","lua_type":"HandleInputObjectCallback\\n"}],"returns":[{"desc":"","lua_type":"ActionHandler\\n"}],"function_type":"static","source":{"line":266,"path":"src/init.luau"}},{"name":"new","desc":"Creates a new [ActionContext] object with the given action handlers.","params":[{"name":"actionHandlers","desc":"","lua_type":"{ ActionHandler }"}],"returns":[{"desc":"","lua_type":"ActionContext\\n"}],"function_type":"static","source":{"line":277,"path":"src/init.luau"}},{"name":"Enter","desc":"Call this when the player enters the gameplay situation in which \\nthis context\'s actions should become available.\\n\\nEmits a warning when called repeatedly without Leaving ([ActionContext:Leave]) first.","params":[],"returns":[],"function_type":"method","source":{"line":298,"path":"src/init.luau"}},{"name":"Bind","desc":"Alias for [ActionContext:Enter].","params":[],"returns":[],"function_type":"method","source":{"line":315,"path":"src/init.luau"}},{"name":"Leave","desc":"Call this when the player leaves the gameplay situation in which\\nthis context\'s actions were available.\\n\\nEmits a warning when called without having called Enter ([ActionContext:Enter]) first.","params":[],"returns":[],"function_type":"method","source":{"line":323,"path":"src/init.luau"}},{"name":"Unbind","desc":"Alias for [ActionContext:Leave].","params":[],"returns":[],"function_type":"method","source":{"line":338,"path":"src/init.luau"}},{"name":"CreateBindAction","desc":"Returns an action handler suitable for use with another [ActionContext].\\n\\nWhen the action\'s input is began, this context will be Entered.\\nWhen the action\'s input is ended or canceled, this context will be Left.\\n\\nUseful for creating input chords, like Ctrl+C and Ctrl+V:\\n\\n```lua\\nlocal innerContext = ActionContext.new({\\n\\t-- in this context, we\'re holding Ctrl\\n\\tActionContext.actionBegin(\\"Copy\\", { Enum.KeyCode.C }, function () print(\\"Copied\\") end),\\n\\tActionContext.actionBegin(\\"Paste\\", { Enum.KeyCode.V }, function () print(\\"Pasted\\") end),\\n})\\nlocal outerContext = ActionContext.new({\\n\\t-- While holding either Control key, the innerContext is entered/left.\\n\\tinnerContext:CreateBindAction(\\"ControlChord\\", { Enum.KeyCode.LeftControl, Enum.KeyCode.RightControl }),\\n})\\nouterContext:Enter()\\n```\\n\\nOr even triads, like Ctrl+Shift+T:\\n\\
1n```lua\\nActionContext.new({\\n\\tActionContext.new({\\n\\t\\t-- in this context, we\'re holding Ctrl\\n\\t\\tActionContext.new({\\n\\t\\t\\t-- in this context, we\'re holding Ctrl then Shift\\n\\t\\t\\tActionContext.actionBegin(\\"Tell the time\\", { Enum.KeyCode.T }, function (inputObject)\\n\\t\\t\\t\\tlocal dt = DateTime.now()\\n\\t\\t\\t\\tprint(dt:FormatUniversalTime(\\"llll\\", \\"en-us\\"))\\n\\t\\t\\t\\treturn Enum.ContextActionResult.Sink\\n\\t\\t\\tend)\\n\\t\\t}):CreateBindAction(\\"ShiftChord\\", { Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift }),\\n\\t}):CreateBindAction(\\"ControlChord\\", { Enum.KeyCode.LeftControl, Enum.KeyCode.RightControl }),\\n}):Enter()\\n```","params":[{"name":"actionName","desc":"","lua_type":"string"},{"name":"inputs","desc":"","lua_type":"{ UserInput }"}],"returns":[{"desc":"","lua_type":"ActionHandler\\n"}],"function_type":"method","source":{"line":379,"path":"src/init.luau"}},{"name":"HandleAction","desc":"Process input related to an action to the appropriate handler within this context. This\\nis automatically called by ContextActionService after this context has been entered and\\nthe actions bound.\\n\\nCall this manually if you want to handle input as if it were performed by the player\\nthrough some other means. For example, if a touchscreen player touches an on-screen button\\nto honk a car horn, you might want the button press input handled by a context that which\\nis entered when the player sits in the car.\\n\\n```lua\\ntextButton.InputBegan:Connect(function (inputObject)\\n\\tcontext:HandleAction(\\"Honk\\", Enum.UserInputState.Begin, inputObject)\\nend)\\n-- (also InputChanged, InputEnded as relevant)\\n```\\n\\nNote that this method ignores whether the context is currently entered or left, so for this\\nexample you would need ensure the on-screen button is shown/hidden when the player enters/leaves\\nthe car.","params":[{"name":"actionName","desc":"","lua_type":"string"},{"name":"userInputState","desc":"","lua_type":"Enum.UserInputState"},{"name":"inputObject","desc":"","lua_type":"InputObject\\n"}],"returns":[{"desc":"","lua_type":"Enum.ContextActionResult?\\n"}],"function_type":"method","source":{"line":423,"path":"src/init.luau"}}],"properties":[],"types":[{"name":"UserInput","desc":"An enum suitable for use with [ContextActionService:BindAction].","lua_type":"Enum.UserInputType | Enum.KeyCode","source":{"line":100,"path":"src/init.luau"}},{"name":"HandleCallback","desc":"An action handler callback which processes arguments that come from [ContextActionService:BindAction].","lua_type":"(userInputState: Enum.UserInputState, inputObject: InputObject) -> Enum.ContextActionResult?","source":{"line":107,"path":"src/init.luau"}},{"name":"HandleInputObjectCallback","desc":"A simpler action handler callback which processes arguments that come from [ContextActionService:BindAction],\\nwith the assumption that a particular UserInputState is desired.\\nUsed with [ActionContext.action], [ActionContext.actionBegin], and [ActionContext.actionEnd].","lua_type":"(inputObject: InputObject) -> Enum.ContextActionResult?","source":{"line":120,"path":"src/init.luau"}},{"name":"ActionHandler","desc":"A table describing a single action to be bound/unbound with [ContextActionService:BindAction]/\\n[ContextActionService:UnbindAction].","lua_type":"{ ActionName: string, Inputs: { UserInput }, Handle: HandleCallback, }","source":{"line":129,"path":"src/init.luau"}}],"name":"ActionContext","desc":"An ActionContext object, also known as just a context, represents a situation in which\\nthe player may take actions by performing input. An action is represented by a table\\nwith `ActionName`, `Inputs` and a `Handle` callback:\\n\\n```lua\\nlocal honkAction = {\\n\\tActionName = \\"Honk\\",\\n\\tInputs = { Enum.KeyCode.H },\\n\\tHandle = function (userInputState: Enum.UserInputState, inputObject: InputObject)\\n\\t\\tif userInputState == Enum.UserInputState.Begin then\\n\\t\\t\\tsound:Play() -- BEEP!\\n\\t\\tend\\n\\t\\t-- (Returning nothing here or nil implies\\n\\t\\t-- returning Enum.ContextActionResult.Sink, see\\n\\t\\t-- docs for ContextActionService:BindAction)\\n\\tend,\\n}\\n```\\n\\nActions like as these are passed in a table to Context.new:\\n\\n```lua\\nlocal carContext = ActionContext.new({ honkAction })\\n```\\n\\nFinally, the context is entered then left at the appropriate time:\\n\\n```lua\\n-- Player gets in the car:\\ncarContext:Enter()\\n\\
1n-- Player exits the car:\\ncarContext:Leave()\\n```\\n\\nNow the player can honk the horn when they are sitting in the car!\\n\\nThe Context library also provides some convenience functions for the creation of simple actions,\\nlike those of one-off key commands:\\n\\n```lua\\nActionContext.new({\\n\\tActionContext.actionBegin(\\"Honk\\", { Enum.KeyCode.H }, function () sound:Play() end)\\n}):Enter()\\n```\\n\\nGot a lot of actions? Organize them into ModuleScripts inside a container:\\n\\n\\n```lua\\nActionContext.fromChildren(container):Enter()\\n```\\n\\nUsing Context:CreateBindAction, it becomes easy to to create input chords. Using this method,\\ndoing one action causes another context to be entered. For example, holding Ctrl enters a\\ncontext in which C and V can be pressed, which is ultimately a Ctrl+C and Ctrl+V sequence:\\n\\n```lua\\nlocal innerContext = ActionContext.new({\\n\\t-- in this context, we\'re holding Ctrl\\n\\tActionContext.actionBegin(\\"Copy\\", { Enum.KeyCode.C }, function () print(\\"Copied\\") end),\\n\\tActionContext.actionBegin(\\"Paste\\", { Enum.KeyCode.V }, function () print(\\"Pasted\\") end),\\n})\\nlocal outerContext = ActionContext.new({\\n\\t-- While holding either Control key, the innerContext is entered/left.\\n\\tinnerContext:CreateBindAction(\\"ControlChord\\", { Enum.KeyCode.LeftControl, Enum.KeyCode.RightControl }),\\n})\\nouterContext:Enter()\\n```\\n\\nIt may be helpful to name `Context` objects after the game state in which they are relevant.\\nIn the above example, `outerContext` might be renamed to `textEditorContext`, and the `innerContext` might be\\nrenamed to `ctrlContext`.","source":{"line":78,"path":"src/init.luau"}}')}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.