The reloj service
Reference for the reloj service. Match time and timers.
DescribesFormato 1, API 1 For those who write code This page is generated from the SDK sources.
On this page
Match time and timers.
The types used in the signatures (Vec3, Texto, the selector) are in the API reference.
Functions and properties of reloj#
| Property | Type | Description |
|---|---|---|
reloj.ahora | number | Simulation seconds since the match started. It stops while paused. |
reloj.cuadro | number | Frame number (60 per second). |
reloj.despues#
reloj.despues(segundos: number, fn: () => void): numberCalls fn once, after segundos. Returns an id for canceling.
From docs/EJEMPLOS.md, «reloj»:
reloj.despues(3, () => interfaz.mensaje(interfaz.t('ya')));reloj.cada#
reloj.cada(segundos: number, fn: () => void): numberCalls fn every segundos. Returns an id for canceling.
From docs/EJEMPLOS.md, «mundo: luces, ambiente y zonas creadas por el script»:
reloj.cada(0.5, () => (faro.encendida = !faro.encendida));reloj.cancelar#
reloj.cancelar(id: number): voidCancels a timer. Takes the id returned by reloj.despues or reloj.cada.
From docs/EJEMPLOS.md, «reloj»:
mundo.alEntrar('meta', () => reloj.cancelar(ciclo));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.
reloj#
import { interfaz, juego, mundo, reloj } from '@greengames/sdk';
juego.alIniciar(() => {
reloj.despues(3, () => interfaz.mensaje(interfaz.t('ya')));
const ciclo = reloj.cada(2, () => {
const puerta = mundo.pieza('puerta');
puerta.solida = !puerta.solida;
puerta.visible = puerta.solida;
});
mundo.alEntrar('meta', () => reloj.cancelar(ciclo));
});Next#
- The actores service
- API reference: the eleven services and the common types.
- Scripts: the rules of a script and how it runs inside the room.