The puntajes service
Reference for the puntajes service. The high-score tables the game declares in its manifest.
DescribesFormato 1, API 1 For those who write code This page is generated from the SDK sources.
On this page
The high-score tables the game declares in its manifest.
The types used in the signatures (Vec3, Texto, the selector) are in the API reference.
Functions and properties of puntajes#
puntajes.registrar#
puntajes.registrar(jugador: Jugador, valor: number, tabla?: string): numberRecords a value in a table from the manifest (the first one by default). Each difficulty has its own list. Returns the rank achieved (1 is the best) or 0 if it did not make the table. Bots do not record scores.
From games/laberinto-de-luces/scripts/principal.ts:
puntajes.registrar(j, tiempo, 'tiempo');puntajes.mejores#
puntajes.mejores(tabla?: string): { nombre: string; valor: number; fecha?: string }[]Top entries of the table for the current difficulty, already sorted.
From docs/EJEMPLOS.md, «puntajes»:
juego.registro('Mejor marca:', puntajes.mejores('puntos')[0]?.valor ?? 'ninguna');puntajes.mejorDe#
puntajes.mejorDe(jugador: Jugador, tabla?: string): number | nullThe player's best value in the table, or null if there is none.
From games/copa-de-bloques/scripts/principal.ts:
const mejor = puntajes.mejorDe(hum, 'puntos');Behavior notes#
The tables are the ones declared in the manifest's puntajes; without tabla the first one is used. You normally do not call registrar: you pass tabla to juego.terminar.
Complete examples#
Complete scripts from docs/EJEMPLOS.md. Each one assumes a scene containing what it names, and the text keys (interfaz.t('...')) must exist in textos of juego.json.
puntajes#
import { juego, mundo, puntajes } from '@greengames/sdk';
juego.alIniciar(() => {
juego.registro('Mejor marca:', puntajes.mejores('puntos')[0]?.valor ?? 'ninguna');
mundo.alEntrar('meta', (_zona, j) => {
// Lo habitual: registrar al terminar. "puntos" está declarada en "puntajes" de juego.json.
juego.terminar({ resultado: 'victoria', puntaje: j.puntos * 10, tabla: 'puntos', de: j });
});
});Next#
- The azar service
- API reference: the eleven services and the common types.
- Scripts: the rules of a script and how it runs inside the room.