beamable-sdk / services / StatsService
Class: StatsService¶
Defined in: src/services/StatsService.ts:49
Extends¶
Constructors¶
Constructor¶
new StatsService(
props):StatsService
Defined in: src/services/StatsService.ts:50
Parameters¶
props¶
Returns¶
StatsService
Overrides¶
ApiService.constructor
Methods¶
get()¶
get(
params):Promise<Record<string,string>>
Defined in: src/services/StatsService.ts:78
Fetches stats for the current player.
Parameters¶
params¶
Returns¶
Promise<Record<string, string>>
Remarks¶
Game domain stats can only be fetched by the game server.
Example¶
// client-side: fetch private or public stats for a client domain
const stats = await beam.stats.get({
accessType: 'private', // or 'public'
stats: ['CURRENT_LEVEL', 'SCORE'], // optional, fetches all stats if not provided
});
// server-side: fetch private or public stats for a game domain
const gameStats = await beamServer.stats(playerId).get({
domainType: 'game',
accessType: 'private', // or 'public'
stats: ['CURRENT_LEVEL', 'SCORE'], // optional, fetches all stats if not provided
});
Throws¶
If the request fails or the stats do not exist.
set()¶
set(
params):Promise<void>
Defined in: src/services/StatsService.ts:134
Sets a stats for the current player.
Parameters¶
params¶
Returns¶
Promise<void>
Remarks¶
Game domain stats can only be set by the game server.
Example¶
const stats = {
CURRENT_LEVEL: '10',
SCORE: '1000',
};
// client-side: set stats for a client domain
await beam.stats.set({
accessType: 'private', // or 'public'
stats,
});
// server-side: set stats for a game domain
await beamServer.stats(playerId).set({
domainType: 'game',
accessType: 'private', // or 'public'
stats,
});
Throws¶
If the request fails or the stats cannot be set.