On this page

klaytonkowalski/library-defold-persist/persist.persist

A simple interface for saving and loading data.

  • GitHub: klaytonkowalski/library-defold-persist — pinned to 2fe3aed
    1. Pick a release from klaytonkowalski/library-defold-persist 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 persist from "persist.persist"

Functions

create(file_name: string, data: any, overwrite?: boolean)

Creates a file with the specified data. If the file already exists, then its data can be overwritten.

Parameters

  • file_name: string
  • data: any
  • overwrite?: boolean

write(file_name: string, key: string, value: any)

Writes data to a file.

Parameters

  • file_name: string
  • key: string
  • value: any

flush(file_name: string, key?: string)

Flushes unsaved data from a file. If a key is specified, then only that field is flushed.

Parameters

  • file_name: string
  • key?: string

save(file_name: string)

Saves data that was written to a file.

Parameters

  • file_name: string

load(file_name: string): {} | undefined

Loads data from a file, including data that has not yet been saved. Returns an object, or undefined if the file does not exist.

Parameters

  • file_name: string

Returns

  • {} | undefined