In Bloxd.io, you can write JavaScript that runs inside the game: from making a block launch a player into the air to creating a shop or a game with rounds and teams. To get started, the documentation recommends visiting Getting started, which explains code blocks, boards, and World Code, as well as where each one runs.
To practice game rules, we’ll build round-based logic in standard JavaScript that can run on its own. Afterward, you can consult Getting started and the API reference to learn how to connect it to Bloxd players and events.
Set up your first experiment
Open the Bloxd.io documentation and start with Getting started. Then, check out Snippets: the page recommends copying an example into a code block and changing it to observe the result. The API reference lets you search for methods, and the search opens with Ctrl K or ⌘ K on Mac.
For the examples in this article, save the code in a file called rondas.js and run it with a JavaScript environment available to you. These blocks do not call the Bloxd API: they are self-contained exercises for defining and checking rules. Don’t paste them into World Code expecting them to control the world; to do that, you need to adapt the logic to the documented functions.
1. Define participants and teams
We’ll start with two teams represented by arrays of names. The function returns a simple list of participants; later, we can reuse it to calculate scores and decide a winner.
// Guarda como rondas.js y ejecuta con un entorno JavaScript.
function crearEquipos() {
return {
Sol: ["Ari", "Noa"],
Luna: ["Kai", "Uma"]
};
}
const equipos = crearEquipos();
console.log(equipos);
The labels and names are sample data, not Bloxd players. In a real game, the Bloxd documentation should explain how to get the player list and assign players to teams. Keeping this distinction clear helps avoid confusing a rules prototype with a working integration.

2. Keep score
Next, we create a points table and a function that adds an amount to a team’s score. The check prevents accidentally recording a score for a name that does not exist in the table.
const puntuacion = {
Sol: 0,
Luna: 0
};
function sumarPunto(equipo, cantidad = 1) {
if (!Object.hasOwn(puntuacion, equipo)) {
throw new Error(`Equipo desconocido: ${equipo}`);
}
if (!Number.isInteger(cantidad) || cantidad < 0) {
throw new Error("La cantidad debe ser un entero no negativo");
}
puntuacion[equipo] += cantidad;
return puntuacion[equipo];
}
sumarPunto("Sol");
sumarPunto("Luna", 2);
console.log(puntuacion);
The function accepts non-negative integers as points. If your game rules allow penalties, you should deliberately change that condition rather than simply removing the validation. In Bloxd, the event that awards points—for example, a player action—would need to come from a documented callback.
3. Resolve the end of a round
The next step compares the scores and returns a status for the round. If there’s a tie, it doesn’t choose a winner based on order or at random: it reports the tie so the game design can decide what to do next.
function resolverRonda(puntos) {
const equipos = Object.keys(puntos);
if (equipos.length === 0) {
throw new Error("Hace falta al menos un equipo");
}
const mejorPuntuacion = Math.max(...Object.values(puntos));
const lideres = equipos.filter(
equipo => puntos[equipo] === mejorPuntuacion
);
if (lideres.length > 1) {
return { estado: "empate", equipos: lideres, puntos: mejorPuntuacion };
}
return { estado: "ganador", equipo: lideres[0], puntos: mejorPuntuacion };
}
console.log(resolverRonda(puntuacion));
With the values from the previous step, Luna is ahead. If both teams finish tied, the function returns an explicit tie result. This output makes it easy to add a custom rule later, such as starting another round; it doesn’t assume how Bloxd handles the end of a match.
4. Simulate a complete round
Now we’ll combine the steps in a function that creates a match, adds points, and returns the result. The simulation uses fixed values, so it always produces the same output: it’s useful for checking the logic without relying on events or an online match.
function simularRonda() {
const puntos = { Sol: 0, Luna: 0 };
puntos.Sol += 1;
puntos.Luna += 2;
puntos.Sol += 1;
return {
puntuacion: puntos,
resultado: resolverRonda(puntos)
};
}
console.log(simularRonda());
The test sequence is fixed in the code: Sol scores two points and Luna scores two. Therefore, the result should be a tie. A repeatable test helps you find errors before replacing these manual increments with actual game actions.
5. Test edge cases
Before connecting anything to the world, test both a win and a tie, and verify that a nonexistent team causes an error. This last block runs checks with standard JavaScript; if any condition fails, it stops the program with an explanation.
function comprobar(condicion, mensaje) {
if (!condicion) {
throw new Error(`Fallo: ${mensaje}`);
}
}
const victoria = resolverRonda({ Sol: 3, Luna: 1 });
comprobar(victoria.estado === "ganador", "debe haber un ganador");
comprobar(victoria.equipo === "Sol", "Sol debe ganar la prueba");
const empate = resolverRonda({ Sol: 2, Luna: 2 });
comprobar(empate.estado === "empate", "debe detectar el empate");
let rechazoEquipo = false;
try {
sumarPunto("Estrellas");
} catch (error) {
rechazoEquipo = error instanceof Error;
}
comprobar(rechazoEquipo, "debe rechazar equipos desconocidos");
console.log("Todas las comprobaciones han pasado.");

Common mistakes when bringing it to Bloxd
The easiest mistake to make is treating this prototype as World Code. It contains no Bloxd API calls or callbacks; it only defines and tests rules in JavaScript. The documentation says callbacks let you respond to actions such as joining, chatting, or breaking blocks, but you need to consult the reference to learn their names and how to use them.
You should also avoid assuming that any name written in the code represents a real player, or that a standard JavaScript method is a Bloxd method. Consult Getting started to distinguish where each tool runs, and search the API for the methods you need. Snippets provides examples you can copy and modify; the Changelog lists changes to the Code API.
The documentation also points to Discord for asking questions, reporting issues, and suggesting features. With the scoring logic now separated, the next step is to find in the API how to read player information and respond to match events, without making up method names.
Source: Bloxd.io

