QuickValue

A value that tells you when it changes.

QuickValue.QuickBool, QuickNumber, QuickString and the other typed constructors make one, holding its Value. Set fires Changed only when the value really changed, and Observe calls back now and on every change. QuickClass(default) makes a class of values of your own.

moduleModules

A built-in module: require("@shotsystem/QuickValue") in a Luau file.

Example

Values that announce changesLuau
--!strict
-- Values that announce their changes, and stay quiet when a value doesn't change.
local QuickValue = require("@shotsystem/QuickValue")

local stock = QuickValue.QuickNumber(3)
stock:Observe(function(value : number)
	print("stock is " .. value)
end)
stock:Set(3)
stock:Set(5)

local open = QuickValue.QuickBool()
print("open starts as " .. tostring(open.Value))
open.Changed:Connect(function()
	print("open is now " .. tostring(open.Value))
end)
open:Set(true)
open:Set(true)
What it printedOutput
stock is 3
stock is 5
open starts as false
open is now true

Constructors

NameArgumentsReturnsDescription
QuickValue.QuickClass(default : any?)QuickClass<any>A class of values with default (a new value given nil takes the default).
QuickValue.QuickBool(value : boolean?)QuickBool
QuickValue.QuickNumber(value : number?)QuickNumber
QuickValue.QuickString(value : string?)QuickString
QuickValue.QuickNilString(value : string?)QuickNilString
QuickValue.QuickNilNumber(value : number?)QuickNilNumber
QuickValue.QuickVector2(value : Vector2?)QuickVector2
QuickValue.QuickDataType(value : any)QuickDataType

A value's methods

NameArgumentsReturnsDescription
value.equals(a : any, b : any)boolean
value:Set(value : any)()Sets the value; Changed fires when it differs by the class's equals.
value:Observe(callback : (any) -> ())QuickSignal.ConnectionCalls callback with the value now and after every change; returns the connection.

A value's fields

NameTypeDescription
ValueT
ChangedQuickSignal.QuickSignal

QuickClass's fields

NameTypeDescription
equals(T, T) -> boolean
new(value : T?) -> QuickType<T>