# Getting started

There are three places to write JavaScript in Bloxd: code blocks, code boards and World Code. Code in any of them controls the game through `api`, in custom games and worlds. Only players who can edit code (the `canEditCode` client option) can write it, but anyone can run a code block or board.

Please use [our Discord](https://discord.gg/playbloxd) to report problems or suggest features.

## Code Blocks

- Find the Code Block by searching in the creative menu.
- Clicking a code block runs its code, unless you are crouching. Players who can edit code open its code by right clicking it.
- Running a code block or board also runs the code blocks and boards touching it, so clicking a `press to code` board next to a code block runs it without opening the code editor.
- A code block doesn't need a `press to code` line, and removes one if you add it.

## Boards

- A board whose text starts with `press to code` on its own line runs the code below that line when someone clicks it.
- Boards only hold a little text: use a code block for anything longer, or split the code across several boards.

## World Code

World Code runs for the whole world instead of when someone clicks. Open it with F8. It defines [Callbacks](https://bloxd.io/docs/callbacks.md), such as `tick` and `onPlayerJoin`, which the game calls when things happen. The [How-Tos](https://bloxd.io/docs/how-to.md) build whole games with it.

## Globals

| Name | Value |
|------|-------|
| `api` | The game API: every method in the [API Reference](https://bloxd.io/docs/api-reference.md) |
| `myId` | The ID of the player running the code, or `null` when nobody is, as in most World Code |
| `playerId` | The same as `myId` |
| `thisPos` | The position of the code block or board running the code, as `[x, y, z]` |
| `api.ownerDbId` | The database ID of the world's owner, or `null` if it has none |

## Logs and results

- `api.log` and `console.log` do the same thing: each shows its values in chat as a `Log:` message.
- When the last line of a code block or board has a value, the player who ran it sees that value as a `Result:` message.

## Next steps

[Snippets](https://bloxd.io/docs/snippets.md) has short pieces of code to copy into a code block and change.
