Skip to Content
defold-typescript libraries
Minit-Games

Minit-Games/minit-defold/minit

Publishes an HTML5 game to the Minit platform. Each call talks to the window.minit runtime the host injects into the page, through html5.run. Call loading_done once the game is ready to show and report_result once when it ends. Outside an HTML5 build every call prints or returns a fixed result, so each is safe to call anywhere.

  • GitHub: Minit-Games/minit-defold — pinned to v1.19.0
    1. Pick a release from Minit-Games/minit-defold releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as minit from "minit.minit"

Functions

loading_done()

Signals the host that the game is booted and ready to show. The host keeps the game hidden until this is called. Outside an HTML5 build it prints loadingDone.

report_result(score: number | string, options?: ReportResultOptions)

Submits the game's final result. Call it exactly once, when the game ends: the host ignores a repeat call, and the SDK warns about it. A higher score ranks better by default. For a time-sorted game (resultSorting fastestTime or slowestTime in meta.json) the score is in seconds, never milliseconds, and fractions are allowed. Outside an HTML5 build it prints the score.

Parameters

  • score: number | string — The result, as a number or a string.
  • options?: ReportResultOptions — The caption, delay and stored slot to send with the result.

get_config_value(key: string, default_value?: string): string

Reads a game config value from the page URL's query parameters (?difficulty=hard). Declare each key the game reads in the config array of its meta.json. The key userData is reserved and always returns the default. Outside an HTML5 build it returns the default.

Parameters

  • key: string — The query parameter to read.
  • default_value?: string — The value returned when the key is absent or reserved. Defaults to "". Upstream names this parameter default.

Returns

  • string

get_user_data(): string | undefined

Returns this player's single stored slot, which report_result writes through its user_data option. Reads the host's window.minit.userData, else the ?userData= URL parameter when the host injected none, else returns undefined. A stored empty value returns "", distinct from undefined. Outside an HTML5 build it returns undefined.

Returns

  • string | undefined

should_show_tutorial(): boolean

Returns whether to run the first-play tutorial. ?tutorial=1 or ?tutorial=true forces it on and ?tutorial=0 or ?tutorial=false forces it off; otherwise it returns false only when the host reports that the player has played the game before. Outside an HTML5 build it returns true.

Returns

  • boolean

get_motion_quality(): "full" | "reduced"

Returns the effects quality to run at. ?motionQuality=full or ?motionQuality=reduced wins; next comes the host's window.minit.motionQuality when it is one of the two; otherwise it returns "reduced" when prefers_reduced_motion returns true, else "full". Outside an HTML5 build it returns "full".

Returns

  • "full" | "reduced"

prefers_reduced_motion(): boolean

Returns whether the player or the operating system prefers reduced motion. ?reducedMotion=1 or ?reducedMotion=true forces true and ?reducedMotion=0 or ?reducedMotion=false forces false; next comes the host's window.minit.prefersReducedMotion when it is a boolean; otherwise it returns whether the browser matches the prefers-reduced-motion: reduce media query, or false when the browser cannot tell. Outside an HTML5 build it returns false.

Returns

  • boolean

get_device_tier(): "low" | "medium" | "high" | "unknown"

Returns the player's device tier. ?deviceTier= set to low, medium, high or unknown wins; next comes the host's window.minit.deviceTier when it is one of the four; otherwise it returns "unknown", which is also its result outside an HTML5 build.

Returns

  • "low" | "medium" | "high" | "unknown"

is_viewable(): boolean

Returns whether the game is visible to the player right now: the host's window.minit.isViewable() when it has one, else whether document.visibilityState is visible. It reads the value again on every call. Outside an HTML5 build it returns true.

Returns

  • boolean

on_viewable_change(fn: (viewable: boolean) => void): () => void

Calls fn each time the game's viewability changes, starting from its value at subscribe time, and returns a function that unsubscribes fn. Lua polls the value every 0.25 s, so a change arrives up to about 250 ms late. Subscribing the same fn again returns its existing unsubscribe, and unsubscribing twice is safe. An error fn raises is printed and does not stop the other subscribers. The poll runs on a timer that belongs to the script that subscribed last and stops with it, so subscribe from a script that outlives the subscription and unsubscribe in its final. Outside an HTML5 build fn is never called and the returned function does nothing.

Parameters

  • fn: (viewable: boolean) => void — Gets true when the game becomes viewable and false when it stops.

Returns

  • () => void

Types

ReportResultOptions

ReportResultOptions.flavor_text?: string

A short caption for the host's result screen and feed. Past 64 characters, counted as a JS string so an emoji counts 2, the SDK warns and the platform cuts it to 64.

ReportResultOptions.delay?: number

How many milliseconds the host waits before showing the result screen.

ReportResultOptions.user_data?: string

Writes this player's single stored slot, which get_user_data reads back. Omit it to leave the slot unchanged; "" is a valid write.

On this page