Skip to main content

Value

A core state representing a single value that can be set or read at any time

TypeSinceScoped
State0.0.1Yes

Constructor

Value(Value : any)

Properties

Value : any

The current state of the value object. Can be either set or read.

ValueRaw : any

Equivalent to using .Value, with the exception of tables. Use this if you run into issues with table values.

Events

Changed

Fired when .Value changes.

Usage

To create a value object, simply call Value(), passing in any value type. In this case, we will be doing a number.

local MyValue = Value(0)

Value objects can lead to a reaction in another state. For example, in either springs or tweens, you can pass a value object in the first parameter. If you do, updating the value updates the animation.

local MyValue = Value(0)

local MySpring = Spring(MyValue, 20, 1) -- Updates whenever MyValue.Value changes

Values can also be used in computeds to update computations, like so:

New(MyFrame, {
Position = Computed(function(Use)
return UDim2.fromScale(Use(XPosition), 0)
end)
})

You can read a value any time by reading the .Value property:

local MyValue = Value(0)

print(MyValue.Value) -- Prints 0
warning

Unlike most state frameworks, Seam does update if a value deep into a table updates. This is done with proxy tables.

Because of this, using tables inside values might cause weird behavior with random features, such as insertion, printing, etc. In cases like these, you may use Value.ValueRaw or GetValue to read table values to fix edge-case issues.