The progreso service
Reference for the progreso service. What is saved for each player from one match to the next, per game.
DescribesFormato 1, API 1 For those who write code This page is generated from the SDK sources.
On this page
What is saved for each player from one match to the next, per game.
The types used in the signatures (Vec3, Texto, the selector) are in the API reference.
Functions and properties of progreso#
progreso.leer#
progreso.leer<T>(jugador: Jugador, clave: string, porDefecto: T): TReads what is saved under that key for that player. If there is nothing, returns porDefecto.
From docs/EJEMPLOS.md, «progreso»:
jugadores.alEntrar((j) => {
const visitas = progreso.leer(j, 'visitas', 0) + 1; // el tercer argumento es el valor por defecto
progreso.guardar(j, 'visitas', visitas);
progreso.guardar(j, 'ultimo', { dificultad: juego.dificultad, escena: juego.escena });
});progreso.guardar#
progreso.guardar(jugador: Jugador, clave: string, valor: unknown): void // JSON only, at most 64 KB per gameSaves a value under that key for that player.
From docs/EJEMPLOS.md, «progreso»:
jugadores.alEntrar((j) => {
const visitas = progreso.leer(j, 'visitas', 0) + 1; // el tercer argumento es el valor por defecto
progreso.guardar(j, 'visitas', visitas);
progreso.guardar(j, 'ultimo', { dificultad: juego.dificultad, escena: juego.escena });
});progreso.borrar#
progreso.borrar(jugador: Jugador, clave: string): voidDeletes that key from the player's saved progress.
From games/isla-taller/scripts/principal.ts:
progreso.borrar(j, CLAVE_PARTIDA);Behavior notes#
It is saved per game and per player, on the player's device. Bots keep their progress in memory.
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.
progreso#
import { juego, jugadores, progreso } from '@greengames/sdk';
juego.alIniciar(() => {
jugadores.alEntrar((j) => {
const visitas = progreso.leer(j, 'visitas', 0) + 1; // el tercer argumento es el valor por defecto
progreso.guardar(j, 'visitas', visitas);
progreso.guardar(j, 'ultimo', { dificultad: juego.dificultad, escena: juego.escena });
});
});Next#
- The puntajes service
- API reference: the eleven services and the common types.
- Scripts: the rules of a script and how it runs inside the room.