Skip to content

Module: Player

Table of contents

Functions

Functions

getConnectedPlayersAsync

getConnectedPlayersAsync(payload?): Promise<ConnectedPlayer[]>

Gets the friends of the player who have also played this game before.

Example

Wortal.player.getConnectedPlayersAsync({
    filter: 'ALL',
    size: 20,
    hoursSinceInvitation: 4,
}).then(players => console.log(players.length);

Parameters

Name Type Description
payload? ConnectedPlayerPayload Options for the friends to get.

Returns

<ConnectedPlayer[]>

Array of connected players.

Throws

NOT_SUPPORTED

RETHROW_FROM_PLATFORM


getDataAsync

getDataAsync(keys): Promise<any>

Gets the game data with the specific keys from the platform's storage.

Example

Wortal.player.getDataAsync(['items', 'lives'])
 .then(data => {
     console.log(data['items']);
     console.log(data['lives']);
 });

Parameters

Name Type Description
keys string[] Array of keys for the data to get.

Returns

Promise<any>

Throws

INVALID_PARAM

NOT_SUPPORTED

RETHROW_FROM_PLATFORM


getID

getID(): string

Gets the player's ID from the platform.

Returns

string

The player's ID.


getName

getName(): string

Gets the player's name on the platform.

Returns

string

The player's name.


getPhoto

getPhoto(): string

Gets the player's photo from the platform.

Returns

string

URL of base64 image for the player's photo.


getSignedPlayerInfoAsync

getSignedPlayerInfoAsync(): Promise<object>

Gets a signed player object that includes the player ID and signature for validation. This can be used to send something to a backend server for validation, such as game or purchase data.

Example

Wortal.player.getSignedPlayerInfoAsync()
 .then(info => {
     myServer.validate(
         info.id,
         info.signature,
         gameDataToValidate,
     )
 });

See

Signature

Returns

Promise<object>

Object with player ID and signature.

Throws

NOT_SUPPORTED

RETHROW_FROM_PLATFORM


isFirstPlay

isFirstPlay(): boolean

Checks whether this is the first time the player has played this game.

Returns

boolean

True if it is the first play. Some platforms always return true.


setDataAsync

setDataAsync(data): Promise<void>

Uploads game data to the platform's storage. Max size is 1MB.

Example

Wortal.player.setDataAsync({
    items: {
        coins: 100,
        boosters: 2
    },
    lives: 3,
});

Parameters

Name Type Description
data Record<string, unknown> Key-value pairs of the data to upload. Nullable values will remove the data.

Returns

Promise<void>

Throws

NOT_SUPPORTED

RETHROW_FROM_PLATFORM