Schema<T = any>
A description of what shape a value must have, which you build with the schema functions to check and convert data.
Tests whether a value fits the schema, and gives the reason when it does not.
Schema:check(value: any) -> (boolean, string?)
example
local ok, reason = stats:check({ name = "Ada", level = 1 })
Use it forchecking an order a player sent from your shop before you act on it.
Gives a copy that fits the schema, or nil and the reason when it cannot.
Schema:convert(value: any) -> (T?, string?)
example
local value, reason = stats:convert({ name = "Ada", level = "3" })
Use it forcleaning up old saved data after you add new fields, which then take their defaults.
valueThe value to convert.
Reads JSON text and converts it to fit the schema, or gives nil and the reason.
Schema:from_json(json: string) -> (T?, string?)
example
local value, reason = stats:from_json('{"name": "Ada", "level": 3}')
Use it forloading settings or level data that you fetched from a web server as JSON text.
Gives a brand new default value that fits the schema.
example
local fresh = stats:default()
Use it forgiving a new player their starting stats the first time they join.