The azar service
Reference for the azar service. Random numbers and choices drawn from the match seed, so a match can be replayed exactly.
DescribesFormato 1, API 1 For those who write code This page is generated from the SDK sources.
On this page
Random numbers and choices drawn from the match seed, so a match can be replayed exactly.
The types used in the signatures (Vec3, Texto, the selector) are in the API reference.
Functions and properties of azar#
azar.numero#
azar.numero(): number // [0, 1)A decimal in [0, 1).
azar.entero#
azar.entero(min: number, max: number): numberAn integer between min and max, both included.
From docs/EJEMPLOS.md, «azar»:
const cantidad = azar.entero(3, 6);azar.entre#
azar.entre(min: number, max: number): numberA decimal in [min, max).
From docs/EJEMPLOS.md, «mundo: crear piezas desde el script»:
const moneda = mundo.crear({
forma: 'cilindro',
posicion: [azar.entre(-10, 10), 1, azar.entre(-10, 10)],
rotacion: [90, 0, 0],
tamano: [0.9, 0.16, 0.9],
material: { color: 'ambar', acabado: 'brillante' },
solida: false,
etiquetas: ['moneda']
});azar.elegir#
azar.elegir<T>(lista: T[]): TA random item from the list.
From docs/EJEMPLOS.md, «azar»:
const premio = azar.elegir(['moneda', 'estrella', 'llave']);azar.mezclar#
azar.mezclar<T>(lista: T[]): T[]A shuffled copy of the list.
From docs/EJEMPLOS.md, «azar»:
const losas = azar.mezclar(mundo.piezas('losa'));azar.suerte#
azar.suerte(p: number): booleantrue with probability p (0 to 1).
From docs/EJEMPLOS.md, «azar»:
if (azar.suerte(0.25)) juego.registro('Partida con premio doble:', premio, cantidad);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.
azar#
import { azar, juego, mundo } from '@greengames/sdk';
juego.alIniciar(() => {
const losas = azar.mezclar(mundo.piezas('losa'));
for (const trampa of losas.slice(0, 3)) trampa.etiquetar('peligro'); // tres trampas distintas cada partida
const premio = azar.elegir(['moneda', 'estrella', 'llave']);
const cantidad = azar.entero(3, 6);
if (azar.suerte(0.25)) juego.registro('Partida con premio doble:', premio, cantidad);
});Next#
- The reloj service
- API reference: the eleven services and the common types.
- Scripts: the rules of a script and how it runs inside the room.