Skip to content
Untitled Sandbox - Developer Documentation
docs/types/Schema

Schema<T = any>

A description of what shape a value must have, which you build with the schema functions to check and convert data.

Schema:check

method

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.

valueThe value to test.

Schema:convert

method

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.

Schema:from_json

method

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.

jsonJSON text.

Schema:default

method

Gives a brand new default value that fits the schema.

Schema:default() -> T
example
local fresh = stats:default()

Use it forgiving a new player their starting stats the first time they join.

↑ ↓ moveEnter openEsc close