Value¶
A node in the accessor tree: what you get from indexing your data, e.g.
Data[player].Coins or data.Inventory.Sword. Every field is a Value;
container fields also expose their children as Values.
The method set is contextual: all fields have Get/Set/Update/
Observe/Changed; number fields add Increment/Decrement; boolean fields
add Toggle; array fields add Insert/Remove/…; dictionary fields add
Remove/Count/…; Scribe.Timed fields add SetTimed/ExtendTimed/Active.
On the client, Set writes are local-only (optimistic UI).
Reserved names
Because method names live on the node, a template field named Get, Set,
Count, Remove, etc. is unreachable through the typed accessor. Scribe
warns about this in Studio.
Core¶
.Get¶
Returns a copy of the field's current value.
.Set¶
Writes a new value (validated and clamped per the declarator). Fires
Changed, replicates, and returns the stored value. Pass replicate = false
to keep the write server-only.
.Update¶
Reads the current value, passes it to transform, and writes the result:
a convenient read-modify-write.
.Clone¶
A deep copy of the value (for tables/buffers you intend to mutate locally).
.Default¶
The field's declared default (a deep copy for tables/buffers, the real datatype for datatype fields). Read-only schema metadata, so it works on the client and server and before data loads. Handy for "reset to default" flows and diffing against the current value.
.Observe¶
Calls callback immediately with the current value, then again on every
change. Returns a disconnect function. The go-to for driving UI.
.Changed¶
Like Observe but fires only on change (no initial call), with both the new
and old values. Returns a disconnect function.
Numbers¶
.Increment¶
Number fields only. Adds amount and returns the new value. Pass false
instead of meta to keep the write server-only.
Pass an EconomyMeta table to auto-emit an economy event
(AnalyticsService:LogEconomyEvent): the currency is this field's name, the
ending balance is the post-change value, and TransactionType, ItemSku,
and per-currency custom Fields come from the table. Increment defaults the
flow to Source.
Data[player].Coins.Increment(50, {
TransactionType = Enum.AnalyticsEconomyTransactionType.Gameplay,
ItemSku = "quest_daily_01",
Fields = { Location = "Lobby" },
})
.Decrement¶
Number fields only. Subtracts amount and returns the new value. Like
Value.Increment but the economy flow defaults to Sink. See the
Economy Analytics guide.
.Min¶
Number fields only. The declared minimum (Scribe.Int(0, { Min = 0 })), or
nil if unbounded. Read-only metadata from the shared schema, so it works on
both the client and the server, and even before data has loaded. Handy for
driving slider ranges or validation off the single source of truth.
.Max¶
Number fields only. The declared maximum, or nil if unbounded. See
Value.Min.
Booleans¶
.Toggle¶
Boolean fields only. Flips the value and returns the new one.
Arrays & Dictionaries¶
.Insert¶
Array fields only. Inserts value (at index, or appended).
.Remove¶
Array fields only. Removes and returns the element at index (or the last),
or nil if empty. (On a dictionary field, Remove(key) deletes that key.)
.RemoveValue¶
Array fields only. Removes the first element equal to value, returning it
and its former index.
.Find¶
Array fields only. The index of the first matching element, or nil.
.Has¶
Array fields only. Whether value is present.
.OnInsert¶
Array fields only. Fires when an element is inserted, with the value and the index it landed at. Returns a disconnect function.
.OnRemove¶
Array fields only. Fires when an element is removed, with the removed value and its former index. Returns a disconnect function.
.OnKeyAdded¶
Dictionary fields only. Fires when a key is added, with the key and its new value. Returns a disconnect function.
.OnKeyRemoved¶
Dictionary fields only. Fires when a key is removed, with the key and its former value. Returns a disconnect function.
.Count¶
Array/dictionary fields. The number of elements/keys.
.Clear¶
Array/dictionary fields. Removes all entries.
Timed¶
.SetTimed¶
Scribe.Timed fields only. Sets value for seconds, after which it
auto-clears back to the declared default (firing Changed). Durations floor
to 1 second (a once-per-second sweep checks expiries) and cap at a finite
~126 years, so SetTimed(value, math.huge) means "effectively permanent".
Note that a later plain Set does NOT cancel the running timer: the field
still resets to its default when the timer lapses. To make a timed value
permanent, re-issue SetTimed(value, math.huge).
.ExtendTimed¶
Scribe.Timed fields only. Adds time to a running timer.
.Active¶
Scribe.Timed fields only. Whether the timer is active, and the seconds
remaining.