### Connect to Component Started Event Source: https://sleitnick.github.io/RbxUtil/api/Component This example shows how to define a component with a specific tag and then connect a function to its 'Started' event. The 'Started' event fires whenever a new instance of the component is successfully started, allowing for post-initialization logic to be executed. ```lua local MyComponent = Component.new({Tag = "MyComponent"}) MyComponent.Started:Connect(function(component) end) ``` -------------------------------- ### Started Event Source: https://sleitnick.github.io/RbxUtil/api/Component Fired when a new instance of a component is started. ```APIDOC ## Started Event ### Description Fired when a new instance of a component is started. ### Method `Started:Connect(function(component) end)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua local MyComponent = Component.new({Tag = "MyComponent"}) MyComponent.Started:Connect(function(component) end) ``` ### Response #### Success Response (200) N/A (This is an event, not an endpoint) #### Response Example N/A ``` -------------------------------- ### Shake:Start() - Start the shake effect Source: https://sleitnick.github.io/RbxUtil/api/Shake The Start() method initiates the shake effect. It must be called before Update() and ideally before OnSignal() or BindToRenderStep(). ```lua shake:Start() ``` -------------------------------- ### Start Timer Immediately Source: https://sleitnick.github.io/RbxUtil/api/Timer Illustrates the usage of the `StartNow` function to immediately start the timer and trigger the `Tick` event. This is useful when an action needs to occur instantly upon starting the timer. ```lua timer:StartNow() ``` -------------------------------- ### Create and Start a Basic Timer Source: https://sleitnick.github.io/RbxUtil/api/Timer Demonstrates how to create a new Timer instance with a specified interval and connect a function to its Tick event to execute periodically. The timer is then started. ```lua local timer = Timer.new(2) timer.Tick:Connect(function() print("Tock") end) timer:Start() ``` -------------------------------- ### Configure Rojo to Sync Wally Packages Source: https://sleitnick.github.io/RbxUtil/docs/intro This JSON configuration shows how to set up Rojo to sync the 'Packages' folder, created by Wally, into Roblox Studio's ReplicatedStorage. This allows the installed modules to be accessible in your game. ```json { "name": "rbx-util-example", "tree": { "$className": "DataModel", "ReplicatedStorage": { "$className": "ReplicatedStorage", "Packages": { "$path": "Packages" } } } } ``` -------------------------------- ### Interact with Other Components using Start Source: https://sleitnick.github.io/RbxUtil/api/Component The Start method is invoked when the component is initiated. By this time, it's safe to acquire references to other components bound to the same instance, enabling inter-component communication. ```lua local MyComponent = Component.new({Tag = "MyComponent"}) local AnotherComponent = require(somewhere.AnotherComponent) function MyComponent:Start() -- e.g., grab another component: local another = self:GetComponent(AnotherComponent) end ``` -------------------------------- ### Install RbxUtil Module with npm Source: https://sleitnick.github.io/RbxUtil/docs/ts Demonstrates how to install a specific RbxUtil module, such as the quaternion library, using npm. This command should be run in your project's terminal. ```bash $ npm install @rbxutil/quaternion ``` -------------------------------- ### Component Lifecycle: Start Method (Lua) Source: https://sleitnick.github.io/RbxUtil/api/Component The `Start` method is executed when the component is activated. It's safe to access other components bound to the same instance at this stage. This is a crucial lifecycle method for inter-component communication. ```lua local MyComponent = Component.new({Tag = "MyComponent"}) local AnotherComponent = require(somewhere.AnotherComponent) function MyComponent:Start() -- e.g., grab another component: local another = self:GetComponent(AnotherComponent) end ``` -------------------------------- ### Define Logger Extension for Components Source: https://sleitnick.github.io/RbxUtil/api/Component This example demonstrates how to create a 'Logger' extension that logs component lifecycle events. The extension is then provided to a new component definition. This allows for observing component behavior during construction, starting, and stopping phases. ```lua local Logger = {} function Logger.Constructing(component) print("Constructing", component) end function Logger.Constructed(component) print("Constructed", component) end function Logger.Starting(component) print("Starting", component) end function Logger.Started(component) print("Started", component) end function Logger.Stopping(component) print("Stopping", component) end function Logger.Stopped(component) print("Stopped", component) end local MyComponent = Component.new({Tag = "MyComponent", Extensions = {Logger}}) ``` -------------------------------- ### Configure Wally Dependencies for RbxUtil Source: https://sleitnick.github.io/RbxUtil/docs/intro This TOML configuration specifies the project details and lists the RbxUtil modules (Signal, TableUtil) as dependencies for Wally. Ensure your project name, version, and registry are correctly set. ```toml [package] name = "your_name/your_project" version = "0.1.0" registry = "https://github.com/UpliftGames/wally-index" realm = "shared" [dependencies] Signal = "sleitnick/signal@^1" TableUtil = "sleitnick/table-util@^1" ``` -------------------------------- ### Lua: LogConfig ModuleScript Examples Source: https://sleitnick.github.io/RbxUtil/api/Log Provides various examples of LogConfig ModuleScripts to configure logger behavior. These scripts can set default log levels or define environment-specific settings for Studio, other environments, and fine-tune by PlaceId or GameId. ```lua -- Set "Info" as default log level for all environments: return "Info" ``` ```lua -- To set a configuration that is different while in Studio: return { Studio = "Debug"; Other = "Warning"; -- "Other" can be anything other than Studio (e.g. could be named "Default") } ``` ```lua -- Fine-tune between server and client: return { Studio = { Server = "Info"; Client = "Debug"; }; Other = "Warning"; } ``` ```lua -- Fine-tune based on PlaceIds: return { Studio = { Server = "Info"; Client = "Debug"; }; Other = { PlaceIds = {123456, 234567} Server = "Severe"; Client = "Warning"; }; } ``` ```lua -- Fine-tune based on GameIds: return { Studio = { Server = "Info"; Client = "Debug"; }; Other = { GameIds = {123456, 234567} Server = "Severe"; Client = "Warning"; }; } ``` ```lua -- Example of full-scale config with multiple environments: return { Studio = { Server = "Debug"; Client = "Debug"; }; Dev = { PlaceIds = {1234567}; Server = "Info"; Client = "Info"; }; Prod = { PlaceIds = {2345678}; Server = "Severe"; Client = "Warning"; }; Default = "Info"; } ``` -------------------------------- ### Create and Start a Simple Camera Shake Source: https://sleitnick.github.io/RbxUtil/api/Shake This snippet demonstrates how to create a new shake instance, configure its properties like fade-in time, frequency, amplitude, and rotation influence, start the shake, and bind it to a render step to apply the shake effect to the camera's CFrame. It uses Lua and assumes the 'Shake' module and 'camera' object are available. ```lua local priority = Enum.RenderPriority.Last.Value local shake = Shake.new() shake.FadeInTime = 0 shake.Frequency = 0.1 shake.Amplitude = 5 shake.RotationInfluence = Vector3.new(0.1, 0.1, 0.1) shake:Start() shake:BindToRenderStep(Shake.NextRenderName(), priority, function(pos, rot, isDone) camera.CFrame *= CFrame.new(pos) * CFrame.Angles(rot.X, rot.Y, rot.Z) end) ``` -------------------------------- ### Use RbxUtil Modules in Roblox Script Source: https://sleitnick.github.io/RbxUtil/docs/intro This Lua script demonstrates how to require and use the Signal and TableUtil modules after they have been installed with Wally and synced via Rojo. It connects a function to a signal that shuffles data and fires it. ```lua -- Reference folder with packages: local Packages = game:GetService("ReplicatedStorage").Packages -- Require the utility modules: local Signal = require(Packages.Signal) local TableUtil = require(Packages.TableUtil) -- Use the modules: local signal = Signal.new() signal:Connect(function(data) local randomizedData = TableUtil.Shuffle(data) print(randomizedData) end) signal:Fire({"A", "B", "C"}) ``` -------------------------------- ### Start Timer Execution Source: https://sleitnick.github.io/RbxUtil/api/Timer Starts the timer. If the timer is already running, this method will have no effect. This is an instance method called on a Timer object. ```lua timer:Start() ``` -------------------------------- ### Initialize Component Instance with Construct Source: https://sleitnick.github.io/RbxUtil/api/Component The Construct method is called before a component starts. It's the ideal place to initialize instance-specific data and properties for your component. ```lua local MyComponent = Component.new({Tag = "MyComponent"}) function MyComponent:Construct() sself.SomeData = 32 sself.OtherStuff = "HelloWorld" end ``` -------------------------------- ### ClientComm Example: Building and Calling a Function Source: https://sleitnick.github.io/RbxUtil/api/Comm Illustrates how to use ClientComm to establish communication and call a server-bound function. It creates a client communicator, builds an object for interaction, and then calls the 'Hello' function. ```lua local ClientComm = require(ReplicatedStorage.Packages.Comm).ClientComm local clientComm = ClientComm.new(somewhere, false, "MyComm") local comm = clientComm:BuildObject() print(comm:Hello()) --> Hi ``` -------------------------------- ### Reset PID Controller to Initial State Source: https://sleitnick.github.io/RbxUtil/api/PID Resets the PID controller to its initial zero start state. This is useful for re-initializing the controller without creating a new instance, for example, after a system reset or significant change. ```lua pid:Reset() ``` -------------------------------- ### Touch Started Event (Lua) Source: https://sleitnick.github.io/RbxUtil/api/Touch This snippet illustrates the signature for the TouchStarted event, a proxy for UserInputService.TouchStarted. It provides the InputObject for the touch and a processed flag. ```lua Touch.TouchStarted: Signal<( touch: InputObject, processed: boolean )> ``` -------------------------------- ### ServerComm Example: Binding a Function Source: https://sleitnick.github.io/RbxUtil/api/Comm Demonstrates how to use ServerComm to bind a function that can be called by clients. This function takes a Player object as input and returns a string. ```lua local ServerComm = require(ReplicatedStorage.Packages.Comm).ServerComm local serverComm = ServerComm.new(somewhere, "MyComm") serverComm:BindFunction("Hello", function(player: Player) return "Hi" end) ``` -------------------------------- ### Sequent: Priority Usage Source: https://sleitnick.github.io/RbxUtil/api/Sequent Provides an example of how to connect a callback function to a Sequent with a specific priority level, using the predefined constants from Sequent.Priority. ```lua sequent:Connect(fn, Sequent.Priority.Highest) ``` -------------------------------- ### Create and Use RBXUtil Timer Source: https://sleitnick.github.io/RbxUtil/api/Timer Demonstrates the basic usage of the Timer class to create a timer that fires a Tick event at a specified interval. It shows how to connect a callback function to the Tick event and start the timer. ```lua local timer = Timer.new(2) timer.Tick:Connect(function() print("Tock") end) timer:Start() ``` -------------------------------- ### Create a Simplified Timer with Callback Source: https://sleitnick.github.io/RbxUtil/api/Timer Shows how to use the `simple` function to create a timer that directly executes a callback function at a given interval. This example includes a basic usage and a more advanced one specifying the update signal and time function. ```lua -- Basic: Timer.simple(1, function() print("Tick") end) -- Using other arguments: Timer.simple(1, function() print("Tick") end, true, RunService.Heartbeat, os.clock) ``` -------------------------------- ### Get All Component Instances - RbxUtil Component Source: https://sleitnick.github.io/RbxUtil/api/Component Gets a table array of all existing component objects associated with a specific component class. For example, if a component class is linked to the 'MyComponent' tag, this method returns all instances with that tag. ```lua local MyComponent = Component.new({Tag = "MyComponent"}) local components = MyComponent:GetAll() for _,component in ipairs(components) do component:DoSomethingHere() end ``` -------------------------------- ### Retrieve All Component Instances Source: https://sleitnick.github.io/RbxUtil/api/Component Explains how to get a table containing all active instances of a specific component class. This is useful for iterating over all components of a certain type, for example, if multiple instances exist in the game attached to different Roblox instances. The `GetAll` method returns an array of component objects. ```lua local MyComponent = Component.new({Tag = "MyComponent"}) -- ... local components = MyComponent:GetAll() for _,component in ipairs(components) do component:DoSomethingHere() end ``` -------------------------------- ### Sequent: Basic Usage and Connection Source: https://sleitnick.github.io/RbxUtil/api/Sequent Demonstrates the basic instantiation of a Sequent, connecting callbacks with different priorities, and firing events. It shows how to handle event values and cancel event propagation. ```lua local sequent = Sequent.new() sequent:Connect( function(event) print("Got value", event.Value) event:Cancel() end, Sequent.Priority.Highest, ) sequent:Connect( function(event) print("This won't print!") end, Sequent.Priority.Lowest, ) sequent:Fire("Test") ``` -------------------------------- ### Initialize PID Controller Source: https://sleitnick.github.io/RbxUtil/api/PID Constructs a new PID controller instance. It requires minimum and maximum output values, along with the proportional (kp), integral (ki), and derivative (kd) gain coefficients to define the controller's behavior and operational range. ```lua local pid = PID.new(0, 1, 0.1, 0, 0) ``` -------------------------------- ### Create and Configure a Simple Shake Source: https://sleitnick.github.io/RbxUtil/api/Shake This snippet demonstrates how to create a new Shake instance, configure its core properties like fade-in time, frequency, and amplitude, and then start the shake. It also shows how to bind the shake's output to a render step to apply the effect to the camera. ```Lua local priority = Enum.RenderPriority.Last.Value local shake = Shake.new() shake.FadeInTime = 0 shake.Frequency = 0.1 shake.Amplitude = 5 shake.RotationInfluence = Vector3.new(0.1, 0.1, 0.1) shake:Start() shake:BindToRenderStep(Shake.NextRenderName(), priority, function(pos, rot, isDone) camera.CFrame *= CFrame.new(pos) * CFrame.Angles(rot.X, rot.Y, rot.Z) end) ``` -------------------------------- ### Instantiate Touch Capturer (Lua) Source: https://sleitnick.github.io/RbxUtil/api/Touch This snippet shows how to construct a new Touch input capturer. This is typically the first step before connecting to any of the Touch events. ```lua Touch.new() ``` -------------------------------- ### Get Trigger Position Source: https://sleitnick.github.io/RbxUtil/api/Gamepad Gets the analog position of a specified trigger (e.g., ButtonL2, ButtonR2). The output is a number between 0 and 1. If deadzoneThreshold is omitted, DefaultDeadzone is applied. ```lua local triggerAmount = gamepad:GetTrigger(Enum.KeyCode.ButtonR2) print(triggerAmount) ``` -------------------------------- ### Define and Initialize a Silo in Lua Source: https://sleitnick.github.io/RbxUtil/api/Silo Demonstrates how to create a new Silo instance with initial state and modifiers, and then dispatch an action to modify the state. It also shows how to retrieve the current state. ```Lua local statsSilo = Silo.new({ -- Initial state: Kills = 0, Deaths = 0, Points = 0, }, { -- Modifiers are functions that modify the state: SetKills = function(state, kills) state.Kills = kills end, AddPoints = function(state, points) state.Points += points end, }) -- Use Actions to modify the state: statsSilo:Dispatch(statsSilo.Actions.SetKills(10)) -- Use GetState to get the current state: print("Kills", statsSilo:GetState().Kills) ``` -------------------------------- ### Initialize ClientComm Source: https://sleitnick.github.io/RbxUtil/api/ClientComm Constructs a new ClientComm instance. The `usePromise` parameter determines if `GetFunction` returns Promises. An optional namespace can be provided for specific server communication. ```lua local clientComm = ClientComm.new(game:GetService("ReplicatedStorage"), true) -- If using a unique namespace with ServerComm, include it as second argument: local clientComm = ClientComm.new(game:GetService("ReplicatedStorage"), true, "MyNamespace") ``` -------------------------------- ### Get ClientRemoteProperty Value Source: https://sleitnick.github.io/RbxUtil/api/ClientRemoteProperty Retrieves the current value of a ClientRemoteProperty. It's recommended to use OnReady() or IsReady() before calling Get() to ensure the value is available, otherwise it might return nil. ```Lua if clientRemoteProperty:IsReady() then local value = clientRemoteProperty:Get() end ``` -------------------------------- ### Get Component Instance from Roblox Instance - RbxUtil Component Source: https://sleitnick.github.io/RbxUtil/api/Component Gets an instance of a component class from a given Roblox instance. Returns nil if the component is not found on that instance. This is a method called on the component class. ```lua local MyComponent = require(somewhere.MyComponent) local myComponentInstance = MyComponent:FromInstance(workspace.SomeInstance) ``` -------------------------------- ### Get ClientRemoteProperty Value Source: https://sleitnick.github.io/RbxUtil/api/ClientRemoteProperty Retrieves the current value of a client-side remote property. It's recommended to ensure the property is ready before calling 'Get' using 'IsReady()' or 'OnReady()' to avoid receiving 'nil'. ```lua local success, initialValue = clientRemoteProperty:OnReady():await() if success then print(initialValue) end ``` -------------------------------- ### Load All Descendant Modules and Call OnStart Source: https://sleitnick.github.io/RbxUtil/api/Loader This snippet demonstrates loading all ModuleScripts under a specified folder that match a name pattern and then invoking their 'OnStart' methods. It utilizes Loader.SpawnAll and Loader.LoadDescendants with a name matching predicate. ```lua local MyModules = ReplicatedStorage.MyModules Loader.SpawnAll( Loader.LoadDescendants(MyModules, Loader.MatchesName("Service$")), "OnStart" ) ``` -------------------------------- ### Example Usage of Network Module in Luau Source: https://sleitnick.github.io/RbxUtil/api/TypedRemote This Luau code provides an example usage of the network module defined previously. It demonstrates how to connect to events and handle the received data on the client-side using intellisense to help with function signatures. ```luau -- Example usage of the above Network module: local Network = require(ReplicatedStorage.Network) -- If you type this out, intellisense will help with what the function signature should be: Network.MyEvent.OnClientEvent:Connect(function(player, str, num) -- Foo end) ``` -------------------------------- ### RemoteFunction Management Source: https://sleitnick.github.io/RbxUtil/api/Net Functions for getting, handling, and invoking RemoteFunctions. ```APIDOC ## Net:RemoteFunction ### Description Gets a RemoteFunction with the given name. Similar to `RemoteEvent`, it handles creation on the server and waiting on the client. ### Method `RemoteFunction` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the RemoteFunction. ### Request Example ```lua local remoteFunction = Net:RemoteFunction("GetPoints") ``` ``` ```APIDOC ## Net:Handle (Server Only) ### Description Sets the invocation function for the given RemoteFunction on the server. This function will be called when a client invokes the RemoteFunction. ### Method `Handle` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the RemoteFunction to handle. - **handler** (function) - Required - The function to be called on the server. It receives the player who invoked the function and any additional arguments. ### Request Example ```lua Net:Handle("GetPoints", function(player) return 10 end) ``` ``` ```APIDOC ## Net:Invoke (Client Only) ### Description Invokes the RemoteFunction with the given arguments on the server. The return value(s) from the server's handler function are returned. ### Method `Invoke` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the RemoteFunction to invoke. - **...** (any) - Optional - Any arguments to pass to the server-side handler. ### Request Example ```lua local points = Net:Invoke("GetPoints") ``` ``` -------------------------------- ### Handle ClientRemoteProperty Readiness with Promises Source: https://sleitnick.github.io/RbxUtil/api/ClientRemoteProperty Provides methods to handle the readiness of a ClientRemoteProperty. OnReady() returns a Promise that resolves with the property's initial value once it's available. IsReady() returns a boolean indicating if the property is ready. ```Lua -- Use andThen clause: clientRemoteProperty:OnReady():andThen(function(initialValue) print(initialValue) end) -- Use await: local success, initialValue = clientRemoteProperty:OnReady():await() if success then print(initialValue) end ``` -------------------------------- ### Create and Match an Option in Lua Source: https://sleitnick.github.io/RbxUtil/api/Option Demonstrates how to create an Option with a value using `Option.Some` and then use the `Match` function to handle both the `Some` and `None` cases. This is a core pattern for safely accessing optional values. ```lua local opt = Option.Some(32) opt:Match { Some = function(num) print("Number", num) end, None = function() print("No value") end, } ``` -------------------------------- ### Client-Side Usage of Typed Network Events Source: https://sleitnick.github.io/RbxUtil/api/TypedRemote This example shows how a client script can consume the typed RemoteEvents defined in the Network module. It demonstrates connecting to a RemoteEvent (`MyEvent`) and provides a clear example of how the arguments (`player`, `str`, `num`) are received, thanks to the type annotations defined on the server. This enables better autocompletion and reduces runtime errors. ```lua -- Example usage of the above Network module: local Network = require(ReplicatedStorage.Network) -- If you type this out, intellisense will help with what the function signature should be: Network.MyEvent:Connect(function(player, str, num) -- Foo end) ``` -------------------------------- ### Initialize Gamepad Instance Source: https://sleitnick.github.io/RbxUtil/api/Gamepad This snippet demonstrates how to initialize a Gamepad instance using the require function from the Input package. It assumes the 'packages' variable is already defined and accessible. ```lua local Gamepad = require(packages.Input).Gamepad local gamepad = Gamepad.new() ``` -------------------------------- ### RemoteProperty: Get Source: https://sleitnick.github.io/RbxUtil/api/RemoteProperty Retrieves the current top-level value of the property. This is the value set by `Set()` or the initial value. ```APIDOC ## RemoteProperty:Get ### Description Returns the top-level value held by the property. This will either be the initial value set, or the last value set with `Set()`. ### Method `RemoteProperty:Get() -> any` ### Parameters None ### Request Example ```lua -- Assuming 'remoteProperty' is an initialized RemoteProperty instance remoteProperty:Set("InitialData") print(remoteProperty:Get()) -- Expected output: "InitialData" remoteProperty:Set("NewTopLevelData") print(remoteProperty:Get()) -- Expected output: "NewTopLevelData" ``` ### Response #### Success Response (200) - `value` (any) - The current top-level value of the property. #### Response Example ```json { "value": "InitialData" } ``` ``` -------------------------------- ### Option Instance Methods Source: https://sleitnick.github.io/RbxUtil/api/Option Provides methods for interacting with an Option instance. ```APIDOC ## Option Instance Methods ### `option:Serialize()` Returns a serialized version of the option. #### Returns - **table** - A table representing the serialized option. ### `option:Match(matches)` Matches against the option. Example: ```lua local opt = Option.Some(32) opt:Match { Some = function(num) print("Number", num) end, None = function() print("No value") end, } ``` #### Parameters - **matches** ({Some: (value: any) -> any, None: () -> any}) - A table containing functions for `Some` and `None` cases. #### Returns - **any** - The result of the executed match function. ### `option:IsSome()` Returns `true` if the option has a value. #### Returns - **boolean** - `true` if the option contains a value, `false` otherwise. ``` -------------------------------- ### Configure Shake Properties Source: https://sleitnick.github.io/RbxUtil/api/Shake This example details various configuration options available for the Shake module. It illustrates how to set properties such as Amplitude, Frequency, FadeInTime, FadeOutTime, SustainTime, Sustain, PositionInfluence, and RotationInfluence to customize the behavior and intensity of the shake effect. ```lua local shake = Shake.new() -- The magnitude of the shake. Larger numbers means larger shakes. shake.Amplitude = 5 -- The speed of the shake. Smaller frequencies mean faster shakes. shake.Frequency = 0.1 -- Fade-in time before max amplitude shake. Set to 0 for immediate shake. shake.FadeInTime = 0 -- Fade-out time. Set to 0 for immediate cutoff. shake.FadeOutTime = 0 -- How long the shake sustains full amplitude before fading out shake.SustainTime = 1 -- Set to true to never end the shake. Call shake:StopSustain() to start the fade-out. shake.Sustain = true -- Multiplies against the shake vector to control the final amplitude of the position. -- Can be seen internally as: position = shakeVector * fadeInOut * positionInfluence shake.PositionInfluence = Vector3.one -- Multiplies against the shake vector to control the final amplitude of the rotation. -- Can be seen internally as: position = shakeVector * fadeInOut * rotationInfluence shake.RotationInfluence = Vector3.new(0.1, 0.1, 0.1) ``` -------------------------------- ### Get Current Preferred Input Source: https://sleitnick.github.io/RbxUtil/api/PreferredInput Retrieves the player's current preferred input method. This function is equivalent to accessing UserInputService.PreferredInput. ```lua local PreferredInput = require(packages.Input).PreferredInput local currentPreferredInput = PreferredInput.get() print(currentPreferredInput) ``` -------------------------------- ### ClientComm Class Source: https://sleitnick.github.io/RbxUtil/api/Comm The ClientComm class is used on the client to get functions, signals, and properties for remote communication. ```APIDOC ## ClientComm ### Description Used on the client to access remote communication objects. ### Properties - **ClientComm** (ClientComm) - The ClientComm class. ### Methods #### GetFunction ```lua GetFunction(parent: Instance, name: string, usePromise: boolean, inboundMiddleware: ClientMiddleware?, outboundMiddleware: ClientMiddleware?): (...: any) -> any ``` - **Description**: Gets a remote function. - **Parameters**: - `parent` (Instance): The parent object of the RemoteFunction. - `name` (string): The name of the remote function. - `usePromise` (boolean): Whether to return a promise. - `inboundMiddleware` (ClientMiddleware, optional): Middleware for incoming function results. - `outboundMiddleware` (ClientMiddleware, optional): Middleware for outgoing function arguments. #### GetSignal ```lua GetSignal(parent: Instance, name: string, inboundMiddleware: ClientMiddleware?, outboundMiddleware: ClientMiddleware?): ClientRemoteSignal ``` - **Description**: Gets a remote signal. - **Parameters**: - `parent` (Instance): The parent object of the RemoteSignal. - `name` (string): The name of the remote signal. - `inboundMiddleware` (ClientMiddleware, optional): Middleware for incoming signal events. - `outboundMiddleware` (ClientMiddleware, optional): Middleware for outgoing signal events. #### GetProperty ```lua GetProperty(parent: Instance, name: string, inboundMiddleware: ClientMiddleware?, outboundMiddleware: ClientMiddleware?): ClientRemoteProperty ``` - **Description**: Gets a remote property. - **Parameters**: - `parent` (Instance): The parent object of the RemoteProperty. - `name` (string): The name of the remote property. - `inboundMiddleware` (ClientMiddleware, optional): Middleware for property updates. - `outboundMiddleware` (ClientMiddleware, optional): Middleware for property updates. ``` -------------------------------- ### Create BufferWriter with BufferUtil Source: https://sleitnick.github.io/RbxUtil/api/BufferUtil Creates a zero-initialized BufferWriter. An optional initial capacity can be provided; otherwise, it defaults to 0. This writer is used for efficiently building buffer data. ```lua local writer = BufferUtil.writer() ``` -------------------------------- ### Get Current Gamepad UserInputType Source: https://sleitnick.github.io/RbxUtil/api/Gamepad Retrieves the Enum.UserInputType that the gamepad object is currently associated with. Returns nil if no gamepad is connected. ```lua gamepad:GetUserInputType() ``` -------------------------------- ### Get RemoteSignal Client Source: https://sleitnick.github.io/RbxUtil/api/ClientComm Returns a `ClientRemoteSignal` object that mirrors a server-side `RemoteSignal`. Allows connecting to events and firing them from the client. ```lua local mySignal = clientComm:GetSignal("MySignal") -- Listen for data from the server: mySignal:Connect(function(message) print("Received message from server:", message) end) -- Send data to the server: mySignal:Fire("Hello!") ``` -------------------------------- ### Option Module Methods Source: https://sleitnick.github.io/RbxUtil/api/Option Documentation for various methods within the Option module, designed to work with optional values. ```APIDOC ## Option Methods ### IsSome #### Description Checks if the option contains a value. ### IsNone #### Description Returns `true` if the option is None. ### Expect #### Description Unwraps the value in the option, otherwise throws an error with `msg` as the error message. ```lua local opt = Option.Some(10) print(opt:Expect("No number")) -> 10 print(Option.None:Expect("No number")) -- Throws an error "No number" ``` #### Parameters - **msg** (string) - The error message to display if the option is None. #### Returns - **value** (any) - The unwrapped value from the option. ### ExpectNone #### Description Throws an error with `msg` as the error message if the value is _not_ None. #### Parameters - **msg** (string) - The error message to display if the option is Some. ### Unwrap #### Description Returns the value in the option, or throws an error if the option is None. #### Returns - **value** (any) - The unwrapped value from the option. ### UnwrapOr #### Description If the option holds a value, returns the value. Otherwise, returns `default`. #### Parameters - **default** (any) - The default value to return if the option is None. #### Returns - **value** (any) - The unwrapped value or the default value. ### UnwrapOrElse #### Description If the option holds a value, returns the value. Otherwise, returns the result of the `defaultFn` function. #### Parameters - **defaultFn** (() -> any) - A function that returns the default value. #### Returns - **value** (any) - The unwrapped value or the result of the default function. ### And #### Description Returns `optionB` if the calling option has a value, otherwise returns None. ```lua local optionA = Option.Some(32) local optionB = Option.Some(64) local opt = optionA:And(optionB) -- opt == optionB local optionA = Option.None local optionB = Option.Some(64) local opt = optionA:And(optionB) -- opt == Option.None ``` #### Parameters - **optionB** (Option) - The option to return if the calling option is Some. #### Returns - **Option** - `optionB` if the calling option is Some, otherwise None. ### AndThen #### Description Applies the function `f` to the contained value if the option is Some, otherwise returns None. If `f` returns an Option, that Option is returned. Otherwise, the result is wrapped in Some. #### Parameters - **f** (() -> Option or any) - The function to apply to the contained value. #### Returns - **Option** - The result of applying `f`. ``` -------------------------------- ### Enable PID Debugging in Studio Source: https://sleitnick.github.io/RbxUtil/api/PID Creates a folder in the Roblox Studio explorer to allow runtime tuning of PID controller attributes. This function is Studio-only and does nothing on a live game server. It requires a name for the debug folder and an optional parent instance. ```lua pid:Debug("CruiseControlDebug", workspace) ``` -------------------------------- ### Get Component Instance - RbxUtil Component Source: https://sleitnick.github.io/RbxUtil/api/Component Retrieves another component instance bound to the same Roblox instance. This is an instance method called on a component instance. ```lua local MyComponent = Component.new({Tag = "MyComponent"}) local AnotherComponent = require(somewhere.AnotherComponent) function MyComponent:Start() local another = self:GetComponent(AnotherComponent) end ``` -------------------------------- ### Get RemoteFunction Client Source: https://sleitnick.github.io/RbxUtil/api/ClientComm Generates a client-side function that invokes a server-side RemoteFunction. If `usePromise` was true during initialization, this function returns a Promise. ```lua -- Server-side: local serverComm = ServerComm.new(someParent) serverComm:BindFunction("MyFunction", function(player, msg) return msg:upper() end) -- Client-side: local clientComm = ClientComm.new(someParent) local myFunc = clientComm:GetFunction("MyFunction") local uppercase = myFunc("hello world") print(uppercase) --> HELLO WORLD -- Client-side, using promises: local clientComm = ClientComm.new(someParent, true) local myFunc = clientComm:GetFunction("MyFunction") myFunc("hi there"):andThen(function(msg) print(msg) --> HI THERE end):catch(function(err) print("Error:", err) end) ``` -------------------------------- ### Get Underlying Buffer using BufferWriter Source: https://sleitnick.github.io/RbxUtil/api/BufferWriter Returns the raw `buffer` object that the BufferWriter is managing. This allows for direct buffer manipulation if needed. ```lua writer:GetBuffer() ``` -------------------------------- ### ClientComm Initialization Source: https://sleitnick.github.io/RbxUtil/api/ClientComm Constructs a new ClientComm object to manage client-side communication. ```APIDOC ## ClientComm.new ### Description Constructs a ClientComm object. If `usePromise` is set to `true`, then `GetFunction` will generate a function that returns a Promise that resolves with the server response. If set to `false`, the function will act like a normal call to a RemoteFunction and yield until the function responds. ### Method `ClientComm.new` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **parent** (Instance) - Required - The parent instance for the communication. * **usePromise** (boolean) - Required - Whether to use Promises for function calls. * **namespace** (string) - Optional - A unique namespace for communication. ### Request Example ```lua local clientComm = ClientComm.new(game:GetService("ReplicatedStorage"), true) -- If using a unique namespace with ServerComm, include it as second argument: local clientComm = ClientComm.new(game:GetService("ReplicatedStorage"), true, "MyNamespace") ``` ### Response #### Success Response (200) * **ClientComm** (ClientComm) - The newly created ClientComm object. #### Response Example ```lua -- (No direct response example, the function returns a ClientComm object) ``` ``` -------------------------------- ### Get Cursor Position using BufferWriter Source: https://sleitnick.github.io/RbxUtil/api/BufferWriter Retrieves the current cursor position within the buffer. This indicates the next byte where data will be written. ```lua writer:GetCursor() ``` -------------------------------- ### Create and Use a Signal Source: https://sleitnick.github.io/RbxUtil/api/Signal Demonstrates the basic usage of the Signal module, including creating a new signal, connecting a callback function, and firing the signal with arguments. This is the fundamental pattern for event handling with this module. ```lua local signal = Signal.new() -- Subscribe to a signal: signal:Connect(function(msg) print("Got message:", msg) end) -- Dispatch an event: signal:Fire("Hello world!") ``` -------------------------------- ### RBXUtil Net API - UnreliableRemoteEvent Source: https://sleitnick.github.io/RbxUtil/api/Net Gets an UnreliableRemoteEvent with the specified name. Similar to RemoteEvent, it creates or waits for the event. ```APIDOC ## GET /websites/sleitnick_github_io_rbxutil/Net/UnreliableRemoteEvent ### Description Retrieves an UnreliableRemoteEvent by its name. Creates it on the server if it doesn't exist, and waits for it on the client. ### Method GET ### Endpoint `/websites/sleitnick_github_io_rbxutil/Net/UnreliableRemoteEvent` ### Parameters #### Query Parameters - **name** (string) - Required - The name of the UnreliableRemoteEvent. ### Request Example ```json { "name": "PositionChanged" } ``` ### Response #### Success Response (200) - **UnreliableRemoteEvent** (UnreliableRemoteEvent) - The requested UnreliableRemoteEvent object. #### Response Example ```json { "UnreliableRemoteEvent": "" } ``` ``` -------------------------------- ### ClientComm Initialization Source: https://sleitnick.github.io/RbxUtil/api/ClientComm Constructs a ClientComm object to manage client-side communication. It can be configured to use promises for asynchronous responses. ```APIDOC ## ClientComm.new ### Description Constructs a ClientComm object. If `usePromise` is set to `true`, then `GetFunction` will generate a function that returns a Promise that resolves with the server response. If set to `false`, the function will act like a normal call to a RemoteFunction and yield until the function responds. ### Method `static` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Parameters - **parent** (Instance) - Required - The parent instance for communication. - **usePromise** (boolean) - Required - Whether to use promises for function calls. - **namespace** (string?) - Optional - A unique namespace for ServerComm. ### Request Example ```lua local clientComm = ClientComm.new(game:GetService("ReplicatedStorage"), true) -- With a unique namespace: local clientComm = ClientComm.new(game:GetService("ReplicatedStorage"), true, "MyNamespace") ``` ### Response #### Success Response (200) - **ClientComm** (ClientComm) - The newly created ClientComm object. #### Response Example ```lua -- No direct response example for constructor, returns the object itself. ``` ``` -------------------------------- ### Get Buffer Capacity using BufferWriter Source: https://sleitnick.github.io/RbxUtil/api/BufferWriter Returns the total capacity (in bytes) of the internal buffer. The capacity may grow automatically as data is added. ```lua writer:GetCapacity() ``` -------------------------------- ### RBXUtil Net API - RemoteFunction Source: https://sleitnick.github.io/RbxUtil/api/Net Gets a RemoteFunction with the specified name. Creates it on the server if it doesn't exist, and waits for it on the client. ```APIDOC ## GET /websites/sleitnick_github_io_rbxutil/Net/RemoteFunction ### Description Retrieves a RemoteFunction by its name. Creates it on the server if it doesn't exist, and waits for it on the client. ### Method GET ### Endpoint `/websites/sleitnick_github_io_rbxutil/Net/RemoteFunction` ### Parameters #### Query Parameters - **name** (string) - Required - The name of the RemoteFunction. ### Request Example ```json { "name": "GetPoints" } ``` ### Response #### Success Response (200) - **RemoteFunction** (RemoteFunction) - The requested RemoteFunction object. #### Response Example ```json { "RemoteFunction": "" } ``` ``` -------------------------------- ### Lua: Basic Logging with Log Class Source: https://sleitnick.github.io/RbxUtil/api/Log Demonstrates basic usage of the Log class, including logging simple messages, rate-limiting logs by count and time, and wrapping logging functions. Ensure the Log class is correctly required. ```lua local Log = require(somewhere.Log) local logger = Log.new() -- Log a simple message: logger:AtInfo():Log("Hello world!") -- Log only every 3 messages: for i = 1,20 do logger:AtInfo():Every(3):Log("Hi there!") end -- Log only every 1 second: for i = 1,100 do logger:AtInfo():AtMostEvery(3, Log.TimeUnit.Seconds):Log("Hello!") task.wait(0.1) end -- Wrap the above example into a function: local log = logger:AtInfo():AtMostEvery(3, Log.TimeUnit.Seconds):Wrap() for i = 1,100 do log("Hello!") task.wait(0.1) end -- Assertion: logger:Assert(typeof(32) == "number", "Somehow 32 is no longer a number") ``` -------------------------------- ### Query.all Source: https://sleitnick.github.io/RbxUtil/api/Query Equivalent to `parent:QueryDescendants(selector)`. Returns all instances matching the selector. ```APIDOC ## Query.all ### Description Returns all instances within the parent that match the given selector. This is a direct equivalent to the `Instance:QueryDescendants()` method. ### Method `static` ### Parameters #### Path Parameters - **parent** (Instance) - The parent instance to start the query from. - **selector** (string) - The selector string to find instances. #### Query Parameters None #### Request Body None ### Request Example ```lua -- Find all parts named 'Wall' under the 'Environment' model: local walls = Query.all(workspace.Environment, "Part{Name = \"Wall\"}") ``` ### Response #### Success Response (200) - **{ Instance }** (Array) - An array containing all instances found matching the selector. #### Response Example ```lua -- Example usage: local buttons = Query.all(game.StarterGui, ".TextButton") for _, button in ipairs(buttons) do print("Found button: " .. button.Name) end ``` ``` -------------------------------- ### Get Stream Buffer Source: https://sleitnick.github.io/RbxUtil/api/stream Retrieves the underlying buffer data from a stream object. This allows direct access to the raw bytes that have been written to the stream. ```lua local buf = stream.buffer(s) ``` -------------------------------- ### Option Static Functions Source: https://sleitnick.github.io/RbxUtil/api/Option Provides static methods for creating and managing Option instances. ```APIDOC ## Option Static Functions ### `Option.Some(value)` Creates an Option instance with the given value. Throws an error if the given value is `nil`. #### Parameters - **value** (T) - The value to wrap in an Option. #### Returns - **Option** - An Option instance containing the provided value. ### `Option.Wrap(value)` Safely wraps the given value as an option. If the value is `nil`, returns `Option.None`, otherwise returns `Option.Some(value)`. #### Parameters - **value** (T) - The value to wrap. #### Returns - **Option | Option** - An Option instance containing the value or `Option.None` if the value is `nil`. ### `Option.Is(obj)` Returns `true` if `obj` is an Option. #### Parameters - **obj** (any) - The object to check. #### Returns - **boolean** - `true` if `obj` is an Option, `false` otherwise. ### `Option.Assert(obj)` Throws an error if `obj` is not an Option. #### Parameters - **obj** (any) - The object to assert as an Option. ### `Option.Deserialize(data)` Deserializes the data into an Option. This data should have come from the `option:Serialize()` method. #### Parameters - **data** (table) - The serialized data representing an Option. #### Returns - **Option** - The deserialized Option instance. ### `Option.__eq(opt1, opt2)` Metamethod to check equality between two options. Returns `true` if both options hold the same value OR both options are None. #### Parameters - **opt1** (Option) - The first option to compare. - **opt2** (Option) - The second option to compare. #### Returns - **boolean** - `true` if the options are equal, `false` otherwise. ``` -------------------------------- ### Get Current State from a Silo in Lua Source: https://sleitnick.github.io/RbxUtil/api/Silo Shows how to retrieve the current state of a Silo instance. This is useful for reading the state without directly modifying it. ```Lua local state = silo:GetState() ``` -------------------------------- ### Get RemoteProperty Client Source: https://sleitnick.github.io/RbxUtil/api/ClientComm Returns a `ClientRemoteProperty` object for observing and interacting with server-side `RemoteProperty`. Supports observing changes, checking readiness, and awaiting data. ```lua local mapInfo = clientComm:GetProperty("MapInfo") -- Observe the initial value of mapInfo, and all subsequent changes: mapInfo:Observe(function(info) print("Current map info", info) end) -- Check to see if data is initially ready: if mapInfo:IsReady() then -- Get the data: local info = mapInfo:Get() end -- Get a promise that resolves once the data is ready (resolves immediately if already ready): mapInfo:OnReady():andThen(function(info) print("Map info is ready with info", info) end) -- Same as above, but yields thread: local success, info = mapInfo:OnReady():await() ``` -------------------------------- ### Lua: Stream Creation and Data Manipulation Source: https://sleitnick.github.io/RbxUtil/api/stream Demonstrates creating a stream, writing byte data, retrieving the underlying buffer, and then creating a new stream from that buffer to read the data back. It also shows how to reposition the stream cursor. ```lua local s = stream.create(4) stream.writeu8(s, 10) stream.writeu8(s, 25) stream.writeu8(s, 2) stream.writeu8(s, 43) local buf = stream.buffer(s) local s = stream.from(buf) print(stream.readu8(s)) -- 10 print(stream.readu8(s)) -- 25 print(stream.readu8(s)) -- 2 print(stream.readu8(s)) -- 43 stream.seek(s, 1) print(stream.readu8(s)) -- 25 ``` -------------------------------- ### Gamepad Class Initialization Source: https://sleitnick.github.io/RbxUtil/api/Gamepad Demonstrates how to create a new instance of the Gamepad class. ```APIDOC ## Gamepad Class ### Description The Gamepad class is part of the Input package and is used to handle gamepad input. ### Initialization ```lua local Gamepad = require(packages.Input).Gamepad local gamepad = Gamepad.new() ``` ### Realm - **Client** ``` -------------------------------- ### Sequent: Connecting Once Source: https://sleitnick.github.io/RbxUtil/api/Sequent Demonstrates the 'Once' method, which is similar to 'Connect' but automatically disconnects the callback after it has been executed a single time. This is useful for one-off event listeners. ```lua local function oneTimeCallback(event) print("This will only print once.") end sequent:Once(oneTimeCallback, Sequent.Priority.Low) ``` -------------------------------- ### Get Gamepad User Input Type (Lua) Source: https://sleitnick.github.io/RbxUtil/api/Gamepad Retrieves the UserInputType associated with the gamepad object. This method returns `nil` if no gamepad is currently connected to the system. ```lua local inputType = gamepad:GetUserInputType() if inputType then print("Gamepad input type: " .. tostring(inputType)) else print("No gamepad connected.") end ``` -------------------------------- ### Get Current Data Size using BufferWriter Source: https://sleitnick.github.io/RbxUtil/api/BufferWriter Returns the current amount of data (in bytes) stored in the buffer. This may be less than the buffer's total capacity. ```lua writer:GetSize() ```