### Create and Manage a Typed Value State in Seam Source: https://context7.com/miagobble/seam/llms.txt Demonstrates creating a typed mutable state, reading its value, updating it (which fires the Changed signal), and listening to changes. Includes an example of type enforcement and cleanup. ```luau local Seam = require(game.ReplicatedFirst.Seam) -- Create a typed value state local health = Seam.Value(100) -- Read the current value print(health.Value) -- 100 -- Update the value (fires .Changed signal) health.Value = 75 print(health.Value) -- 75 -- Listen to changes health.Changed:Connect(function(property, newValue) print("Health changed to:", newValue) -- Health changed to: 50 end) health.Value = 50 -- Type enforcement: assigning a string to a number Value errors local ok, err = pcall(function() health.Value = "full" -- ERROR: Invalid value type! Expected number, got string end) print(ok, err) -- false ...Invalid value type!... -- Cleanup health:Destroy() ``` -------------------------------- ### Safely Get Value from Seam State Source: https://context7.com/miagobble/seam/llms.txt Use GetValue to unwrap a Seam state's value or pass through a raw value. It safely handles nil arguments. ```lua local Seam = require(game.ReplicatedFirst.Seam) local speedState = Seam.Value(42) print(Seam.GetValue(speedState)) -- 42 (unwrapped from state) print(Seam.GetValue(99)) -- 99 (plain number passed through) print(Seam.GetValue(nil)) -- nil (safe nil handling) -- Useful in functions that accept either a state or a literal local function applySpeed(target, speedOrState) local speed = Seam.GetValue(speedOrState) target.WalkSpeed = speed end applySpeed(game.Players.LocalPlayer.Character.Humanoid, speedState) applySpeed(game.Players.LocalPlayer.Character.Humanoid, 16) ``` -------------------------------- ### Reactive Table Mapping with ForPairs in Seam Source: https://context7.com/miagobble/seam/llms.txt Illustrates using Seam.ForPairs to wrap a table state and apply a callback to each entry, creating a new reactive table. It efficiently recomputes only changed entries and demonstrates updating the source table. ```luau local Seam = require(game.ReplicatedFirst.Seam) local playerScores = Seam.Value({ Alice = 10, Bob = 20, Carol = 30, }) -- Map each score to a display string, reacting to table changes local displayStrings = Seam.ForPairs(playerScores, function(Use, key, value) return key .. ": " .. tostring(value) .. " pts" end) print(displayStrings.Value) -- { Alice = "Alice: 10 pts", Bob = "Bob: 20 pts", Carol = "Carol: 30 pts" } -- Update only Bob's score — only Bob's entry is recomputed playerScores.Value = { Alice = 10, Bob = 99, Carol = 30 } print(displayStrings.Value) -- { Alice = "Alice: 10 pts", Bob = "Bob: 99 pts", Carol = "Carol: 30 pts" } displayStrings:Destroy() playerScores:Destroy() ``` -------------------------------- ### Time-keyed callback sequences with EventSequence Source: https://context7.com/miagobble/seam/llms.txt Creates a sequenced timeline of callbacks keyed by cumulative time offsets. Supports Play, Stop, Pause, and Resume controls. Can be looped with a delay. ```luau local Seam = require(game.ReplicatedFirst.Seam) local sequence = Seam.EventSequence({ {0.0, function() print("Phase 1: Start!") end}, {1.0, function() print("Phase 2: After 1 sec") end}, {1.5, function() print("Phase 3: After 2.5 sec") end}, {2.0, function() print("Phase 4: After 4.5 sec") end}, }) -- Loop the sequence with a 1-second delay between loops sequence.Looped = true sequence.LoopDelayTime = 1 sequence.Play() -- Pause mid-sequence task.delay(1.2, function() sequence.Pause() print("Paused at 1.2 seconds") end) -- Resume after 2 extra seconds task.delay(3.2, function() sequence.Resume() end) -- Stop entirely after 8 seconds task.delay(8, function() sequence.Stop() print("Sequence stopped") end) ``` -------------------------------- ### Sync Value state from Instance property with FollowProperty Source: https://context7.com/miagobble/seam/llms.txt Connects to an Instance's GetPropertyChangedSignal and writes the property's new value back into a Value state. Useful for two-way binding. ```luau local Seam = require(game.ReplicatedFirst.Seam) local trackedPosition = Seam.Value(Vector3.zero) local part = Seam.New("Part", { Parent = workspace, Anchored = false, [Seam.FollowProperty("Position")] = trackedPosition, }) -- Whenever Roblox physics moves the part, trackedPosition.Value updates part.Position = Vector3.new(5, 0, 0) -- triggers the signal print(trackedPosition.Value) -- Vector3(5, 0, 0) ``` -------------------------------- ### New: Construct and Hydrate Roblox Instances with Seam Source: https://context7.com/miagobble/seam/llms.txt Use Seam.New to create new Instances from class names or hydrate existing ones. Properties are set directly, and Seam state objects are automatically tracked. Supports custom Component classes. ```luau local Seam = require(game.ReplicatedFirst.Seam) local isVisible = Seam.Value(true) local labelText = Seam.Value("Hello, Seam!") -- Construct a ScreenGui with reactive children local gui = Seam.New("ScreenGui", { Parent = game.Players.LocalPlayer.PlayerGui, ResetOnSpawn = false, [Seam.Children] = { Seam.New("Frame", { Size = UDim2.fromScale(0.4, 0.2), AnchorPoint = Vector2.new(0.5, 0.5), Position = UDim2.fromScale(0.5, 0.5), BackgroundColor3 = Color3.fromRGB(30, 30, 30), Visible = isVisible, -- reactive: updates whenever isVisible changes [Seam.Children] = { Seam.New("TextLabel", { Size = UDim2.fromScale(1, 1), Text = labelText, -- reactive TextColor3 = Color3.new(1, 1, 1), BackgroundTransparency = 1, }) } }) } }) -- Reactively toggle visibility isVisible.Value = false -- Frame disappears isVisible.Value = true -- Frame reappears -- Hydrate an existing instance local existingPart = workspace:FindFirstChild("MyPart") if existingPart then Seam.New(existingPart, { BrickColor = BrickColor.new("Bright red"), }) end ``` -------------------------------- ### Create Derived State with Computed in Seam Source: https://context7.com/miagobble/seam/llms.txt Shows how to create a read-only derived state using Seam.Computed. The computation re-runs automatically when dependent states change. Includes listening to derived state changes and cleanup. ```luau local Seam = require(game.ReplicatedFirst.Seam) local baseSpeed = Seam.Value(16) local multiplier = Seam.Value(2) -- Derived state: re-computes whenever baseSpeed or multiplier changes local speed = Seam.Computed(function(Use) return Use(baseSpeed) * Use(multiplier) end) print(speed.Value) -- 32 baseSpeed.Value = 20 print(speed.Value) -- 40 -- Listen to derived changes speed.Changed:Connect(function() print("Speed is now:", speed.Value) end) multiplier.Value = 3 -- prints "Speed is now: 60" speed:Destroy() baseSpeed:Destroy() multiplier:Destroy() ``` -------------------------------- ### Children: Attach and Reconcile Child Instances with Seam Source: https://context7.com/miagobble/seam/llms.txt Use the Seam.Children declaration key within Seam.New to attach child instances. It accepts an array of Instances or a Computed state that returns an array. When backed by a Computed, children are automatically reconciled. ```luau local Seam = require(game.ReplicatedFirst.Seam) local items = Seam.Value({"Apple", "Banana", "Cherry"}) -- Computed that maps item names to TextLabel instances local itemLabels = Seam.Computed(function(Use) local labels = {} for _, name in Use(items) do table.insert(labels, Seam.New("TextLabel", { Size = UDim2.new(1, 0, 0, 30), Text = name, BackgroundTransparency = 1, })) end return labels end) local listFrame = Seam.New("Frame", { Parent = game.Players.LocalPlayer.PlayerGui:FindFirstChildOfClass("ScreenGui"), Size = UDim2.fromOffset(200, 300), [Seam.Children] = itemLabels, -- auto-reconciles when items changes }) -- Adding an item re-runs the Computed, old labels are destroyed, new set is parented items.Value = {"Apple", "Banana", "Cherry", "Date"} ``` -------------------------------- ### Sync Value state from Instance attribute with FollowAttribute Source: https://context7.com/miagobble/seam/llms.txt Mirrors an Instance's attribute value into a Value state. Connects to GetAttributeChangedSignal. Useful for reactive attribute updates. ```luau local Seam = require(game.ReplicatedFirst.Seam) local healthState = Seam.Value(100) local character = Seam.New("Model", { Parent = workspace, [Seam.Attribute("Health")] = healthState, -- set attribute reactively [Seam.FollowAttribute("Health")] = healthState, -- also mirror changes back }) -- External code modifies the attribute character:SetAttribute("Health", 75) print(healthState.Value) -- 75 (mirrored back into the state) ``` -------------------------------- ### Create Per-Frame Reactive State with Rendered Source: https://context7.com/miagobble/seam/llms.txt Use `Seam.Rendered` to create a state that recalculates its value every frame. The callback receives delta time and is useful for real-time displays. Accumulation must be managed externally if needed. ```luau local Seam = require(game.ReplicatedFirst.Seam) -- Counts elapsed seconds since the state was created local elapsed = Seam.Rendered(function(dt) -- dt is seconds since last frame -- (accumulation must be managed externally if needed) return os.clock() end) -- Bind to a TextLabel — updates every frame automatically local label = Seam.New("ScreenGui", { Parent = game.Players.LocalPlayer.PlayerGui, [Seam.Children] = { Seam.New("TextLabel", { Size = UDim2.fromScale(0.3, 0.05), Text = elapsed, -- Seam binds the Rendered state directly }) } }) -- Manual read at any time print(elapsed.Value) -- e.g. 1723.42 (os.clock value) elapsed:Destroy() ``` -------------------------------- ### One-shot callback on Instance Destroyed Source: https://context7.com/miagobble/seam/llms.txt Calls :Once() on the Instance's Destroying event, firing the callback exactly once when the Instance is removed. Useful for cleanup. ```luau local Seam = require(game.ReplicatedFirst.Seam) local prop = Seam.New("Part", { Parent = workspace, Anchored = true, [Seam.Destroyed] = function() print("Prop was destroyed — cleaning up game state") end, }) prop:Destroy() -- Output: "Prop was destroyed — cleaning up game state" ``` -------------------------------- ### Tags: Apply CollectionService Tags During Instance Construction with Seam Source: https://context7.com/miagobble/seam/llms.txt Use the Seam.Tags declaration key within Seam.New to apply multiple CollectionService tags to an Instance at construction time. It accepts an array of tag strings. ```luau local Seam = require(game.ReplicatedFirst.Seam) local enemy = Seam.New("Model", { Parent = workspace, Name = "Goblin", [Seam.Tags] = {"Enemy", "NPC", "Damageable"}, }) -- Tags are queryable via CollectionService local CollectionService = game:GetService("CollectionService") print(CollectionService:HasTag(enemy, "Enemy")) -- true print(CollectionService:HasTag(enemy, "Damageable")) -- true ``` -------------------------------- ### Debug Log Seam State Changes Source: https://context7.com/miagobble/seam/llms.txt Inspect connects to a state's .Changed signal and logs value changes. Requires a DebugName and returns a connection that can be disconnected. ```lua local Seam = require(game.ReplicatedFirst.Seam) local score = Seam.Value(0) local connection = Seam.Inspect(score, "PlayerScore") score.Value = 10 -- Output: SEAM_INSPECT | PlayerScore | Value changed to 10 score.Value = 50 -- Output: SEAM_INSPECT | PlayerScore | Value changed to 50 -- Disconnect when done debugging connection:Disconnect() score.Value = 100 -- no output ``` -------------------------------- ### Connect to named Instance events with OnEvent Source: https://context7.com/miagobble/seam/llms.txt Connects a callback to an Instance's named event when used inside a New property table. The connection is stored and can be cleaned up via Destroy(). ```luau local Seam = require(game.ReplicatedFirst.Seam) local clickCount = Seam.Value(0) local button = Seam.New("TextButton", { Parent = game.Players.LocalPlayer.PlayerGui:FindFirstChildOfClass("ScreenGui"), Size = UDim2.fromOffset(200, 50), Text = "Click me", [Seam.OnEvent("Activated")] = function() clickCount.Value += 1 print("Clicked! Total:", clickCount.Value) end, [Seam.OnEvent("MouseEnter")] = function() print("Mouse entered button") end, }) ``` -------------------------------- ### Connect to State or Instance .Changed Signal Source: https://context7.com/miagobble/seam/llms.txt Use `OnChanged` to react to changes in Seam states or Roblox Instances. The callback receives the property name and its new value. Ensure the Instance exists before connecting. ```luau local Seam = require(game.ReplicatedFirst.Seam) local score = Seam.Value(0) -- Connect to a Seam state's Changed signal local connection = Seam.OnChanged(score, function(property, newValue) print(`Score {property} changed to {newValue}`) end) score.Value = 10 -- "Score Value changed to 10" score.Value = 25 -- "Score Value changed to 25" connection:Disconnect() -- Also works on Roblox Instances local part = workspace:FindFirstChild("MyPart") Seam.OnChanged(part, function(property, newValue) print(`Part.{property} = {tostring(newValue)}`) end) ``` -------------------------------- ### Inspect Source: https://context7.com/miagobble/seam/llms.txt Debug-logs all changes to a Seam state, requiring a `DebugName` for identification. ```APIDOC ## Inspect ### Description Debug-log all changes to a state. Connects to a state's `.Changed` signal and prints a formatted log line every time the value changes. Requires a `DebugName` string for identification in the output. Returns the `RBXScriptConnection` so it can be disconnected later. ### Usage ```luau local Seam = require(game.ReplicatedFirst.Seam) local score = Seam.Value(0) local connection = Seam.Inspect(score, "PlayerScore") score.Value = 10 -- Output: SEAM_INSPECT | PlayerScore | Value changed to 10 score.Value = 50 -- Output: SEAM_INSPECT | PlayerScore | Value changed to 50 connection:Disconnect() score.Value = 100 -- no output ``` ``` -------------------------------- ### Scope Source: https://context7.com/miagobble/seam/llms.txt Creates a managed container that tracks states, instances, and connections for automatic lifetime management. Scopes can be nested and inherit constructors. ```APIDOC ## Scope ### Description `Scope` creates a managed container that tracks states, instances, and connections. When `scope:Destroy()` is called, everything added to the scope is cleaned up. Scopes are initialized with a dictionary of Seam constructors, which become callable methods on the scope that auto-register their outputs for cleanup. Inner scopes inherit parent constructors and are destroyed with their parent. ### Method Seam.Scope(constructors) ### Parameters #### Path Parameters - **constructors** (table) - Required - A dictionary of Seam constructors (e.g., `Seam.Value`, `Seam.New`) to be made available as methods on the scope. ### Usage #### Creating a Scope ```luau local Seam = require(game.ReplicatedFirst.Seam) local scope = Seam.Scope({ Value = Seam.Value, Computed = Seam.Computed, Spring = Seam.Spring, New = Seam.New, OnChanged = Seam.OnChanged, }) ``` #### Using Scope Methods ```luau local hp = scope:Value(100) local maxHp = scope:Value(200) local hpFrac = scope:Computed(function(Use) return Use(hp) / Use(maxHp) end) local smoothFrac = scope:Spring(hpFrac, 15, 0.9) local bar = scope:New("Frame", { Parent = game.Players.LocalPlayer.PlayerGui:FindFirstChildOfClass("ScreenGui"), Size = UDim2.new(smoothFrac, 0, 0, 20), BackgroundColor3 = Color3.fromRGB(0, 200, 0), }) ``` #### Inner Scopes ```luau local innerScope = scope:InnerScope({ Value = Seam.Value, New = Seam.New, }) local tempLabel = innerScope:New("TextLabel", { Parent = bar, Size = UDim2.fromScale(1, 1), Text = "HP", }) innerScope:Destroy() -- Cleans up tempLabel only ``` #### Destroying a Scope ```luau scope:Destroy() -- Cleans up all tracked objects ``` ``` -------------------------------- ### Define a Reusable Labeled Slider Component with Seam Source: https://context7.com/miagobble/seam/llms.txt This snippet demonstrates how to define a custom `LabeledSlider` component using Seam's `Component` class. It includes initialization of reactive state and construction of the UI elements. Use this pattern for creating encapsulated, reusable UI elements. ```luau local Seam = require(game.ReplicatedFirst.Seam) -- Define a reusable labeled slider component local LabeledSlider = Seam.Component({ Init = function(self, scope, props) -- Store reactive state on the component instance self.currentValue = scope and scope:Value(props.Default or 0) or Seam.Value(props.Default or 0) end, Construct = function(self, scope, props) local label = Seam.Computed(function(Use) return (props.Label or "Value") .. ": " .. tostring(Use(self.currentValue)) end) return Seam.New("Frame", { Size = UDim2.fromOffset(300, 40), [Seam.Children] = { Seam.New("TextLabel", { Size = UDim2.fromScale(1, 1), Text = label, BackgroundTransparency = 1, }) } }) end, }) -- Use inside New like any other class local sliderFrame = Seam.New(LabeledSlider, { Label = "Volume", Default = 75, }) -- Or instantiate standalone local scope = Seam.Scope({ New = Seam.New, Value = Seam.Value, Computed = Seam.Computed }) local anotherSlider = scope:New(LabeledSlider, { Label = "Brightness", Default = 50 }) scope:Destroy() ``` -------------------------------- ### Physics-Based Animation with Spring State Source: https://context7.com/miagobble/seam/llms.txt Utilize `Seam.Spring` to animate numeric states using a spring simulation. It smoothly interpolates towards a target value with configurable speed and dampening. Supports all numeric Roblox value types. ```luau local Seam = require(game.ReplicatedFirst.Seam) local targetPosition = Seam.Value(Vector3.new(0, 0, 0)) -- Spring follows targetPosition with speed=20, dampening=0.8 (slightly under-damped) local springPosition = Seam.Spring(targetPosition, 20, 0.8) -- Bind the spring output directly to a part's Position local part = Seam.New("Part", { Parent = workspace, Anchored = true, Position = springPosition, }) -- Move the target; the part smoothly springs to the new position targetPosition.Value = Vector3.new(10, 5, 0) -- Read current interpolated position at any time print(springPosition.Value) -- e.g. Vector3(0.3, 0.15, 0) shortly after the change -- Read current velocity print(springPosition.Velocity) -- e.g. Vector3(6.1, 3.0, 0) -- Teleport the spring to a position without velocity carry-over springPosition.Value = Vector3.new(10, 5, 0) -- Adjust parameters at runtime springPosition.Speed = 30 springPosition.Dampening = 1.0 -- Critically damped springPosition:Destroy() targetPosition:Destroy() ``` -------------------------------- ### Auto-destroy Instance with Lifetime Source: https://context7.com/miagobble/seam/llms.txt Registers an Instance with DebrisService for cleanup after a specified delay. No manual delay is needed. ```luau local Seam = require(game.ReplicatedFirst.Seam) -- Bullet that auto-destroys after 3 seconds local bullet = Seam.New("Part", { Parent = workspace, Anchored = false, Size = Vector3.new(0.2, 0.2, 1), [Seam.Lifetime] = 3, -- destroyed after 3 seconds }) -- The part disappears automatically; no manual task.delay needed ``` -------------------------------- ### Manage Lifetime with Seam Scope Source: https://context7.com/miagobble/seam/llms.txt Use `Seam.Scope` to create a managed container for states, instances, and connections. Calling `scope:Destroy()` cleans up all added resources. Inner scopes inherit constructors and are destroyed with their parent. ```luau local Seam = require(game.ReplicatedFirst.Seam) -- Define the set of Seam objects this scope can create local scope = Seam.Scope({ Value = Seam.Value, Computed = Seam.Computed, Spring = Seam.Spring, New = Seam.New, OnChanged = Seam.OnChanged, }) -- All objects created through scope methods are tracked automatically local hp = scope:Value(100) local maxHp = scope:Value(200) local hpFrac = scope:Computed(function(Use) return Use(hp) / Use(maxHp) end) local smoothFrac = scope:Spring(hpFrac, 15, 0.9) local bar = scope:New("Frame", { Parent = game.Players.LocalPlayer.PlayerGui:FindFirstChildOfClass("ScreenGui"), Size = UDim2.new(smoothFrac, 0, 0, 20), -- driven by spring BackgroundColor3 = Color3.fromRGB(0, 200, 0), }) hp.Value = 50 -- bar smoothly shrinks -- Inner scope for temporary UI elements local innerScope = scope:InnerScope({ Value = Seam.Value, New = Seam.New, }) local tempLabel = innerScope:New("TextLabel", { Parent = bar, Size = UDim2.fromScale(1, 1), Text = "HP", }) -- Destroying innerScope cleans up tempLabel only innerScope:Destroy() -- Destroying the parent scope cleans up hp, maxHp, hpFrac, smoothFrac, bar scope:Destroy() ``` -------------------------------- ### OnChanged Source: https://context7.com/miagobble/seam/llms.txt Connects a callback to the `.Changed` signal of any Seam state or Roblox Instance. The callback receives the property name that changed and its new value. ```APIDOC ## OnChanged ### Description Connects a callback to the `.Changed` signal of any Seam state or Roblox Instance. The callback receives the property name that changed and its new value. ### Method Seam.OnChanged(target, callback) ### Parameters #### Path Parameters - **target** (Seam State or Roblox Instance) - Required - The state or instance to listen for changes on. - **callback** (function) - Required - The function to execute when a change occurs. It receives `property` (string) and `newValue` (any). ### Request Example ```luau local Seam = require(game.ReplicatedFirst.Seam) local score = Seam.Value(0) local connection = Seam.OnChanged(score, function(property, newValue) print(`Score {property} changed to {newValue}`) end) score.Value = 10 connection:Disconnect() ``` ### Response #### Success Response (Connection Object) - **Disconnect** (function) - A function to disconnect the listener. ``` -------------------------------- ### Attribute: Bind Reactive State to Instance Attributes with Seam Source: https://context7.com/miagobble/seam/llms.txt Use Seam.Attribute to bind a Seam state or a raw value to an Instance attribute. The attribute updates reactively when the bound state changes. This is a curried declaration. ```luau local Seam = require(game.ReplicatedFirst.Seam) local teamColor = Seam.Value("Red") local part = Seam.New("Part", { Parent = workspace, Anchored = true, [Seam.Attribute("Team")] = teamColor, -- sets Part:SetAttribute("Team", "Red") }) -- Attribute updates when state changes teamColor.Value = "Blue" print(part:GetAttribute("Team")) -- "Blue" -- With a static (non-reactive) value local marker = Seam.New("Part", { Parent = workspace, [Seam.Attribute("IsSpawnPoint")] = true, }) print(marker:GetAttribute("IsSpawnPoint")) -- true ``` -------------------------------- ### GetValue Source: https://context7.com/miagobble/seam/llms.txt Safely unwraps a Seam state's value or passes through a raw value. Handles nil inputs gracefully. ```APIDOC ## GetValue ### Description Safely unwrap a state or pass through a raw value. Returns `state.Value` if the argument is a Seam state, or returns the argument unchanged if it is a plain value. Returns `nil` safely if the argument is `nil`. ### Usage ```luau local Seam = require(game.ReplicatedFirst.Seam) local speedState = Seam.Value(42) print(Seam.GetValue(speedState)) -- 42 print(Seam.GetValue(99)) -- 99 print(Seam.GetValue(nil)) -- nil local function applySpeed(target, speedOrState) local speed = Seam.GetValue(speedOrState) target.WalkSpeed = speed end ``` ``` -------------------------------- ### SetValue Source: https://context7.com/miagobble/seam/llms.txt Safely sets a Seam state's value or returns a raw value. Handles nil inputs without error. ```APIDOC ## SetValue ### Description Safely set a state's value or return a raw value. Sets `state.Value = newValue` if the first argument is a Seam state with a `.Value` field, and always returns `newValue`. If the first argument is `nil`, returns `newValue` without error. ### Usage ```luau local Seam = require(game.ReplicatedFirst.Seam) local lives = Seam.Value(3) Seam.SetValue(lives, 2) print(lives.Value) -- 2 Seam.SetValue(nil, 10) -- returns 10, no crash local function decrementLives(livesOrNil) local current = Seam.GetValue(livesOrNil) or 0 Seam.SetValue(livesOrNil, current - 1) end decrementLives(lives) print(lives.Value) -- 1 ``` ``` -------------------------------- ### OnAttached Source: https://context7.com/miagobble/seam/llms.txt Connects a callback to a Seam state's `AttachedToInstance` signal, which fires whenever the state is bound to an Instance property. ```APIDOC ## OnAttached ### Description Connects a callback to a Seam state's `AttachedToInstance` signal, which fires whenever the state is bound to an Instance property (e.g., passed as a value inside `New`). The callback receives the Instance the state was attached to. ### Method Seam.OnAttached(state, callback) ### Parameters #### Path Parameters - **state** (Seam State) - Required - The Seam state to listen for attachment events on. - **callback** (function) - Required - The function to execute when the state is attached. It receives `instance` (Instance). ### Request Example ```luau local Seam = require(game.ReplicatedFirst.Seam) local transparency = Seam.Value(0) Seam.OnAttached(transparency, function(instance) print("transparency state was attached to:", instance:GetFullName()) end) local frame = Seam.New("Frame", { Parent = game.Players.LocalPlayer.PlayerGui:FindFirstChildOfClass("ScreenGui"), Size = UDim2.fromScale(0.5, 0.5), BackgroundTransparency = transparency, }) ``` ``` -------------------------------- ### Safely Set Value on Seam State Source: https://context7.com/miagobble/seam/llms.txt SetValue updates a Seam state's value or returns a raw value. It safely handles nil arguments and returns the new value. ```lua local Seam = require(game.ReplicatedFirst.Seam) local lives = Seam.Value(3) Seam.SetValue(lives, 2) print(lives.Value) -- 2 -- Safe with nil (no error) Seam.SetValue(nil, 10) -- returns 10, no crash -- Useful in generic utilities that don't know if they hold a state local function decrementLives(livesOrNil) local current = Seam.GetValue(livesOrNil) or 0 Seam.SetValue(livesOrNil, current - 1) end decrementLives(lives) print(lives.Value) -- 1 ``` -------------------------------- ### Eased Animation with Tween State Source: https://context7.com/miagobble/seam/llms.txt Employ `Seam.Tween` for eased animations driven by `TweenInfo`. It supports all numeric Roblox types and allows the `TweenInfo` to be reactive for runtime adjustments to duration and easing style. ```luau local Seam = require(game.ReplicatedFirst.Seam) local targetColor = Seam.Value(Color3.fromRGB(255, 0, 0)) local tweenInfo = TweenInfo.new( 0.4, -- duration (seconds) Enum.EasingStyle.Quad, Enum.EasingDirection.Out ) local smoothColor = Seam.Tween(targetColor, tweenInfo) -- Bind to a Frame's BackgroundColor3 local frame = Seam.New("Frame", { Parent = game.Players.LocalPlayer.PlayerGui:FindFirstChildOfClass("ScreenGui"), Size = UDim2.fromScale(0.5, 0.5), BackgroundColor3 = smoothColor, }) -- Trigger the tween to green targetColor.Value = Color3.fromRGB(0, 255, 0) -- Teleport instantly (no tween) smoothColor.Value = Color3.fromRGB(0, 0, 255) -- Swap the TweenInfo at runtime smoothColor.TweenInfo = TweenInfo.new(1.0, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out) smoothColor:Destroy() targetColor:Destroy() ``` -------------------------------- ### OnAttributeChanged Source: https://context7.com/miagobble/seam/llms.txt A curried connection that reacts to an attribute change inside `New`. It connects to `GetAttributeChangedSignal` on the Instance when used inside a `New` property table. ```APIDOC ## OnAttributeChanged ### Description A curried connection: `OnAttributeChanged("AttributeName")` returns a declaration key that connects to `GetAttributeChangedSignal` on the Instance when used inside a `New` property table. ### Method Seam.OnAttributeChanged(attributeName) ### Parameters #### Path Parameters - **attributeName** (string) - Required - The name of the attribute to listen for changes on. ### Request Example ```luau local Seam = require(game.ReplicatedFirst.Seam) local npc = Seam.New("Model", { Parent = workspace, Name = "NPC", [Seam.Attribute("Health")] = 100, [Seam.OnAttributeChanged("Health")] = function() local hp = npc:GetAttribute("Health") print("NPC health changed to:", hp) if hp <= 0 then print("NPC died!") end end, }) pc:SetAttribute("Health", 50) npc:SetAttribute("Health", 0) ``` ``` -------------------------------- ### IsComponent Source: https://context7.com/miagobble/seam/llms.txt Checks if a value is a Seam `Component`. ```APIDOC ## IsComponent ### Description Type-check: is a value a Seam Component? Returns `true` if the given value is a Seam `Component` (has the `__SEAM_COMPONENT` symbol). Returns `false` otherwise. ### Usage ```luau local Seam = require(game.ReplicatedFirst.Seam) local ButtonComponent = Seam.Component({ Init = function(self, scope, props) end, Construct = function(self, scope, props) return Seam.New("TextButton", { Text = props.Label or "Button", Size = UDim2.fromOffset(120, 40), }) end, }) print(Seam.IsComponent(ButtonComponent)) -- true print(Seam.IsComponent(Seam.Value(0))) -- false print(Seam.IsComponent({})) -- false ``` ``` -------------------------------- ### React to Attribute Changes with OnAttributeChanged Source: https://context7.com/miagobble/seam/llms.txt Use `OnAttributeChanged` within a `New` property table to react to specific attribute changes on an Instance. This is a curried function that connects to the Instance's `GetAttributeChangedSignal`. ```luau local Seam = require(game.ReplicatedFirst.Seam) local npc = Seam.New("Model", { Parent = workspace, Name = "NPC", [Seam.Attribute("Health")] = 100, [Seam.OnAttributeChanged("Health")] = function() local hp = npc:GetAttribute("Health") print("NPC health changed to:", hp) if hp <= 0 then print("NPC died!") end end, }) pc:SetAttribute("Health", 50) -- "NPC health changed to: 50" pc:SetAttribute("Health", 0) -- "NPC health changed to: 0" + "NPC died!" ``` -------------------------------- ### IsState Source: https://context7.com/miagobble/seam/llms.txt Checks if a value is a recognized Seam state object (e.g., `Value`, `Computed`, `Spring`). ```APIDOC ## IsState ### Description Type-check: is a value a Seam state? Returns `true` if the given value is a recognized Seam state object (`Value`, `Computed`, `Spring`, `Tween`, `Rendered`, or `ForPairs` instance). Returns `false` for all other values including `nil`, primitives, and plain tables. ### Usage ```luau local Seam = require(game.ReplicatedFirst.Seam) local myValue = Seam.Value(10) local mySpring = Seam.Spring(myValue, 10, 1) local plainTable = { foo = "bar" } print(Seam.IsState(myValue)) -- true print(Seam.IsState(mySpring)) -- true print(Seam.IsState(plainTable)) -- false print(Seam.IsState(42)) -- false print(Seam.IsState(nil)) -- false local function setProp(instance, prop, valueOrState) if Seam.IsState(valueOrState) then valueOrState(instance, prop) -- attach state to instance property else instance[prop] = valueOrState end end ``` ``` -------------------------------- ### Check if a Value is a Seam Component Source: https://context7.com/miagobble/seam/llms.txt IsComponent returns true if the value is a Seam Component (has the __SEAM_COMPONENT symbol). It returns false otherwise. ```lua local Seam = require(game.ReplicatedFirst.Seam) local ButtonComponent = Seam.Component({ Init = function(self, scope, props) end, Construct = function(self, scope, props) return Seam.New("TextButton", { Text = props.Label or "Button", Size = UDim2.fromOffset(120, 40), }) end, }) print(Seam.IsComponent(ButtonComponent)) -- true print(Seam.IsComponent(Seam.Value(0))) -- false print(Seam.IsComponent({})) -- false ``` -------------------------------- ### React When State is Bound to an Instance with OnAttached Source: https://context7.com/miagobble/seam/llms.txt Use `OnAttached` to execute a callback when a Seam state is bound to an Instance property, such as within a `Seam.New` call. The callback receives the Instance the state was attached to. ```luau local Seam = require(game.ReplicatedFirst.Seam) local transparency = Seam.Value(0) -- Listen before attaching Seam.OnAttached(transparency, function(instance) print("transparency state was attached to:", instance:GetFullName()) end) -- Creating this New call triggers AttachedToInstance local frame = Seam.New("Frame", { Parent = game.Players.LocalPlayer.PlayerGui:FindFirstChildOfClass("ScreenGui"), Size = UDim2.fromScale(0.5, 0.5), BackgroundTransparency = transparency, -- fires OnAttached callback }) -- Output: "transparency state was attached to: PlayerGui.ScreenGui.Frame" ``` -------------------------------- ### Make Seam State Immutable Source: https://context7.com/miagobble/seam/llms.txt LockValue permanently prevents writes to a Value state's .Value property. Attempts to mutate after locking will raise an error. ```lua local Seam = require(game.ReplicatedFirst.Seam) local config = Seam.Value("ProductionMode") -- Lock after initial configuration Seam.LockValue(config) print(config.Value) -- "ProductionMode" -- Any attempt to mutate now errors local ok, err = pcall(function() config.Value = "DebugMode" end) print(ok) -- false print(err) -- "Attempt to modify value when locked." ``` -------------------------------- ### LockValue Source: https://context7.com/miagobble/seam/llms.txt Makes a Seam `Value` state immutable, preventing further writes and disconnecting internal signals. ```APIDOC ## LockValue ### Description Make a `Value` state immutable. Permanently prevents further writes to a `Value` state's `.Value` property. After locking, any attempt to assign `.Value` raises an error. Locking also destroys the value's internal Trove (disconnects all internal signals). Only `Value` states can be locked. ### Usage ```luau local Seam = require(game.ReplicatedFirst.Seam) local config = Seam.Value("ProductionMode") Seam.LockValue(config) print(config.Value) -- "ProductionMode" local ok, err = pcall(function() config.Value = "DebugMode" end) print(ok) -- false print(err) -- "Attempt to modify value when locked." ``` ``` -------------------------------- ### Check if a Value is a Seam State Source: https://context7.com/miagobble/seam/llms.txt IsState returns true if the value is a recognized Seam state object (Value, Computed, Spring, etc.). It returns false for primitives, tables, and nil. ```lua local Seam = require(game.ReplicatedFirst.Seam) local myValue = Seam.Value(10) local mySpring = Seam.Spring(myValue, 10, 1) local plainTable = { foo = "bar" } print(Seam.IsState(myValue)) -- true print(Seam.IsState(mySpring)) -- true print(Seam.IsState(plainTable)) -- false print(Seam.IsState(42)) -- false print(Seam.IsState(nil)) -- false -- Useful in generic property setters local function setProp(instance, prop, valueOrState) if Seam.IsState(valueOrState) then valueOrState(instance, prop) -- attach state to instance property else instance[prop] = valueOrState end end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.