Skip to main content

MetricUnitSystems

The well-known MetricUnitSystems, and a builder for Roblox systems at a game's own scale.

  • METRIC: SI and the metric units people read, such as km, kg, L and °C. The default for every value.
  • US_CUSTOMARY: the United States: US gallons, quarts and cups, short tons, mpg (US).
  • IMPERIAL: Britain: imperial gallons, pints and fluid ounces, stone, mpg (UK).
  • US_CUSTOMARY_AND_IMPERIAL: the units both share, which the two fall back to: miles, feet and inches, mph, pounds, BTU, horsepower, psi, °F.
  • ROBLOX: studs against the default avatar, 28 cm each, with studs per second and Roblox mass units.

A value shows itself in the system of the unit it was made from. To show it in another, convert it or ask that system to format it:

local MINI = MetricUnitSystems.roblox({ name = "robloxMini", metersPerStud = 0.028 })

local speed = MINI:New(part.AssemblyLinearVelocity.Magnitude, "studPerSecond")
MetricUnit.format(speed) -- in the game's studs per second
MetricUnitSystems.IMPERIAL:Format(speed) -- in mph, for a player who chose imperial
MetricUnit.format(speed:ToMetric()) -- in m/s

Types​

RobloxSystemConfig​

interface RobloxSystemConfig {
name: string
metersPerStud: number
fallback: MetricUnitSystem?--

defaults to METRIC

}

The options for MetricUnitSystems.roblox.

Properties​

METRIC​

MetricUnitSystems.METRIC: MetricUnitSystem

SI and the metric units people read.

US_CUSTOMARY_AND_IMPERIAL​

MetricUnitSystems.US_CUSTOMARY_AND_IMPERIAL: MetricUnitSystem

The units the United States and Britain share, which MetricUnitSystems.US_CUSTOMARY and MetricUnitSystems.IMPERIAL fall back to before metric.

US_CUSTOMARY​

MetricUnitSystems.US_CUSTOMARY: MetricUnitSystem

United States customary units.

IMPERIAL​

MetricUnitSystems.IMPERIAL: MetricUnitSystem

British imperial units.

ROBLOX​

MetricUnitSystems.ROBLOX: MetricUnitSystem

Studs against the default Roblox avatar, 28 cm each.

Functions​

roblox​

MetricUnitSystems.roblox(config: RobloxSystemConfig) → MetricUnitSystem

A Roblox system at a stud of metersPerStud: stud, studPerSecond, studPerSecondSquared and robloxMassUnit at that scale, shown for lengths, speeds, accelerations and masses, and fallback (metric by default) for everything else.

local GIANT = MetricUnitSystems.roblox({ name = "robloxGiant", metersPerStud = 2.8 })
GIANT:New(10, "stud"):In("meter") -- 28

getSystemOfUnit​

MetricUnitSystems.getSystemOfUnit(unit: UnitDefinition) → MetricUnitSystem?

The system that declares unit: a game's own system for its units, a well-known one such as IMPERIAL for imperialPint, or nil for units every system shares, such as the second.

Show raw api
{
    "functions": [
        {
            "name": "roblox",
            "desc": "A Roblox system at a stud of `metersPerStud`: `stud`, `studPerSecond`, `studPerSecondSquared` and\n`robloxMassUnit` at that scale, shown for lengths, speeds, accelerations and masses, and `fallback` (metric by\ndefault) for everything else.\n\n```lua\nlocal GIANT = MetricUnitSystems.roblox({ name = \"robloxGiant\", metersPerStud = 2.8 })\nGIANT:New(10, \"stud\"):In(\"meter\") -- 28\n```",
            "params": [
                {
                    "name": "config",
                    "desc": "",
                    "lua_type": "RobloxSystemConfig"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "MetricUnitSystem"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 168,
                "path": "src/metricutils/src/Shared/Systems/MetricUnitSystems.lua"
            }
        },
        {
            "name": "getSystemOfUnit",
            "desc": "The system that declares `unit`: a game's own system for its units, a well-known one such as `IMPERIAL` for\n`imperialPint`, or nil for units every system shares, such as the second.",
            "params": [
                {
                    "name": "unit",
                    "desc": "",
                    "lua_type": "UnitDefinition"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "MetricUnitSystem?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 215,
                "path": "src/metricutils/src/Shared/Systems/MetricUnitSystems.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "METRIC",
            "desc": "SI and the metric units people read.",
            "lua_type": "MetricUnitSystem",
            "source": {
                "line": 40,
                "path": "src/metricutils/src/Shared/Systems/MetricUnitSystems.lua"
            }
        },
        {
            "name": "US_CUSTOMARY_AND_IMPERIAL",
            "desc": "The units the United States and Britain share, which [MetricUnitSystems.US_CUSTOMARY] and\n[MetricUnitSystems.IMPERIAL] fall back to before metric.",
            "lua_type": "MetricUnitSystem",
            "source": {
                "line": 91,
                "path": "src/metricutils/src/Shared/Systems/MetricUnitSystems.lua"
            }
        },
        {
            "name": "US_CUSTOMARY",
            "desc": "United States customary units.",
            "lua_type": "MetricUnitSystem",
            "source": {
                "line": 114,
                "path": "src/metricutils/src/Shared/Systems/MetricUnitSystems.lua"
            }
        },
        {
            "name": "IMPERIAL",
            "desc": "British imperial units.",
            "lua_type": "MetricUnitSystem",
            "source": {
                "line": 130,
                "path": "src/metricutils/src/Shared/Systems/MetricUnitSystems.lua"
            }
        },
        {
            "name": "ROBLOX",
            "desc": "Studs against the default Roblox avatar, 28 cm each.",
            "lua_type": "MetricUnitSystem",
            "source": {
                "line": 189,
                "path": "src/metricutils/src/Shared/Systems/MetricUnitSystems.lua"
            }
        }
    ],
    "types": [
        {
            "name": "RobloxSystemConfig",
            "desc": "The options for [MetricUnitSystems.roblox].",
            "fields": [
                {
                    "name": "name",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "metersPerStud",
                    "lua_type": "number",
                    "desc": ""
                },
                {
                    "name": "fallback",
                    "lua_type": "MetricUnitSystem?",
                    "desc": "defaults to METRIC"
                }
            ],
            "source": {
                "line": 149,
                "path": "src/metricutils/src/Shared/Systems/MetricUnitSystems.lua"
            }
        }
    ],
    "name": "MetricUnitSystems",
    "desc": "The well-known [MetricUnitSystem]s, and a builder for Roblox systems at a game's own scale.\n\n- `METRIC`: SI and the metric units people read, such as km, kg, L and °C. The default for every value.\n- `US_CUSTOMARY`: the United States: US gallons, quarts and cups, short tons, mpg (US).\n- `IMPERIAL`: Britain: imperial gallons, pints and fluid ounces, stone, mpg (UK).\n- `US_CUSTOMARY_AND_IMPERIAL`: the units both share, which the two fall back to: miles, feet and inches, mph,\n  pounds, BTU, horsepower, psi, °F.\n- `ROBLOX`: studs against the default avatar, 28 cm each, with studs per second and Roblox mass units.\n\nA value shows itself in the system of the unit it was made from. To show it in another, convert it or ask\nthat system to format it:\n\n```lua\nlocal MINI = MetricUnitSystems.roblox({ name = \"robloxMini\", metersPerStud = 0.028 })\n\nlocal speed = MINI:New(part.AssemblyLinearVelocity.Magnitude, \"studPerSecond\")\nMetricUnit.format(speed) -- in the game's studs per second\nMetricUnitSystems.IMPERIAL:Format(speed) -- in mph, for a player who chose imperial\nMetricUnit.format(speed:ToMetric()) -- in m/s\n```",
    "source": {
        "line": 26,
        "path": "src/metricutils/src/Shared/Systems/MetricUnitSystems.lua"
    }
}