Skip to Content
defold-typescript libraries
megalanthusdefold-gamepush

megalanthus/defold-gamepush/gamepush.core.player

GamePush player: login, sync, fields and state, with the player events.

  • GitHub: megalanthus/defold-gamepush — pinned to v1.4.1
    1. Pick a release from megalanthus/defold-gamepush 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 core_player from "gamepush.core.player"

Functions

is_logged_in(): boolean

Whether the player is logged in.

Returns

  • boolean

has_any_credentials(): boolean

Whether the player uses any sign-in method: a cookie, an account or a secret code.

Returns

  • boolean

is_logged_in_by_platform(): boolean

Whether the player is logged in on the platform.

Returns

  • boolean

sync(parameters?: SyncParameters, callback?: () => void)

Syncs the player with the server.

Parameters

  • parameters?: SyncParameters — The sync options, or nil for the defaults.
  • callback?: () => void — Called when the sync finishes.

load(callback?: () => void)

Loads the player from the server, overwriting the local one.

Parameters

  • callback?: () => void — Called when the load finishes.

login(callback?: (result: boolean) => void)

Opens the login flow.

Parameters

  • callback?: (result: boolean) => void — Receives whether the player logged in.

logout(callback?: (result: boolean) => void)

Logs the player out.

Parameters

  • callback?: (result: boolean) => void — Receives whether the player logged out.

enable_auto_sync(parameters: AutoSyncParameters)

Turns on automatic syncing for a storage. Raises when the table is missing.

Parameters

  • parameters: AutoSyncParameters

disable_auto_sync(parameters: DisableAutoSyncParameters)

Turns off automatic syncing for a storage. Raises when the table is missing.

Parameters

  • parameters: DisableAutoSyncParameters

fetch_fields(callback?: () => void)

Fetches the list of player fields.

Parameters

  • callback?: () => void — Called when the fetch finishes.

id(): number

The player's id.

Returns

  • number

score(): number

The player's score, 0 when it has none.

Returns

  • number

name(): string

The player's name, "" when it has none.

Returns

  • string

avatar(): string

The URL of the player's avatar.

Returns

  • string

is_stub(): boolean

Whether the player is a stub: empty, or still holding only default data.

Returns

  • boolean

fields(): Record<string, unknown>[]

The player's field descriptions.

Returns

  • Record<string, unknown>[]

get(key: string): string | number | boolean

The value of field key.

Parameters

  • key: string

Returns

  • string | number | boolean

set(key: string, value: string | number | boolean)

Sets field key to value. Raises unless value is a string, number or boolean.

Parameters

  • key: string
  • value: string | number | boolean

add(key: string, value: number)

Adds value to field key. Raises unless value is a number.

Parameters

  • key: string
  • value: number

toggle(key: string)

Inverts field key.

Parameters

  • key: string

has(key: string): boolean

Whether field key exists and is not empty: not 0, "", false or null.

Parameters

  • key: string

Returns

  • boolean

to_json(): Record<string, unknown>

The player's state as a table.

Returns

  • Record<string, unknown>

from_json(parameters?: Record<string, unknown>)

Sets the player's state from a table of field keys and values.

Parameters

  • parameters?: Record<string, unknown> — The state, in the shape to_json returns.

reset()

Resets the player's state to the defaults.

remove()

Removes the player: resets its fields and clears its id.

get_field(key: string): Record<string, unknown>

The description of field key.

Parameters

  • key: string

Returns

  • Record<string, unknown>

get_field_name(key: string): string

The translated name of field key.

Parameters

  • key: string

Returns

  • string

get_field_variant_name(key: string, value: string): string

The translated name of variant value of enum field key. Raises unless value is a string.

Parameters

  • key: string
  • value: string

Returns

  • string

Variables

stats: typeof import('gamepush.core.player_stats')

The player's statistics, the same table as gamepush.core.player_stats.

callbacks: PlayerCallbacks

The player event handlers.

Types

SyncParameters

SyncParameters.override?: boolean

Overwrite the player stored on the server with the local one.

SyncParameters.silent?: boolean

Passed through as the SDK's silent sync option.

AutoSyncParameters

AutoSyncParameters.interval: number

The sync interval, in seconds.

AutoSyncParameters.storage: "preferred" | "cloud" | "platform" | "local"

The storage to sync automatically.

DisableAutoSyncParameters

DisableAutoSyncParameters.storage: "preferred" | "cloud" | "platform" | "local"

The storage to stop syncing automatically.

PlayerCallbacks

PlayerCallbacks.sync?: (success: boolean) => void

The player was synced.

PlayerCallbacks.load?: (success: boolean) => void

The player was loaded from the server.

PlayerCallbacks.login?: (success: boolean) => void

The player logged in.

PlayerCallbacks.logout?: (success: boolean) => void

The player logged out.

PlayerCallbacks.fetch_fields?: (success?: boolean) => void

The player's field list was fetched; success is set on HTML5 and absent elsewhere.

PlayerCallbacks.change?: () => void

A player field changed.

On this page

Functionsis_logged_in(): booleanhas_any_credentials(): booleanis_logged_in_by_platform(): booleansync(parameters?: SyncParameters, callback?: () => void)load(callback?: () => void)login(callback?: (result: boolean) => void)logout(callback?: (result: boolean) => void)enable_auto_sync(parameters: AutoSyncParameters)disable_auto_sync(parameters: DisableAutoSyncParameters)fetch_fields(callback?: () => void)id(): numberscore(): numbername(): stringavatar(): stringis_stub(): booleanfields(): Record<string, unknown>[]get(key: string): string | number | booleanset(key: string, value: string | number | boolean)add(key: string, value: number)toggle(key: string)has(key: string): booleanto_json(): Record<string, unknown>from_json(parameters?: Record<string, unknown>)reset()remove()get_field(key: string): Record<string, unknown>get_field_name(key: string): stringget_field_variant_name(key: string, value: string): stringVariablesstats: typeof import('gamepush.core.player_stats')callbacks: PlayerCallbacksTypesSyncParametersSyncParameters.override?: booleanSyncParameters.silent?: booleanAutoSyncParametersAutoSyncParameters.interval: numberAutoSyncParameters.storage: "preferred" | "cloud" | "platform" | "local"DisableAutoSyncParametersDisableAutoSyncParameters.storage: "preferred" | "cloud" | "platform" | "local"PlayerCallbacksPlayerCallbacks.sync?: (success: boolean) => voidPlayerCallbacks.load?: (success: boolean) => voidPlayerCallbacks.login?: (success: boolean) => voidPlayerCallbacks.logout?: (success: boolean) => voidPlayerCallbacks.fetch_fields?: (success?: boolean) => voidPlayerCallbacks.change?: () => void