# Scripts and bots

A community's **scripts** are code Games Communities runs for it when something happens: a member joins, writes a
message or a `!command`, buys a game, presses a button, or a timer fires. Scripts post as the community's bot, keep the
community's data, draw cards and talk to its widgets. There is nothing to host: the service runs them.

Every community can have scripts, whatever its size.

## Where to write them

- **In Games Communities**: the group's settings › **Code** is one folder: `site/` (the group's page: HTML, CSS,
  JavaScript) and `scripts/`. **+ New** › **A script** (an empty JavaScript page) or **A blueprint** (boxes and wires,
  no typing). Luau, Python and WebAssembly run too.
- **In your own editor**: **Code** › **Your editor** (in the app) puts the same folder on your PC and opens VS Code,
  Cursor or any editor; each save is saved to the group. **AI** › **AI Code** works in that folder too. From a browser
  or a terminal: [gc-cli dev](tools.md#gc-cli-dev).

## Learn

**Code and AI helpers…** › **Learn** has 11 small quests that teach scripting step by step: *Say hi*, *Say their name*,
*Your first command*, *Say it back*, *Roll a die*, *Count the messages*, *Points for each member*, *Give a flair*,
*Settings, no code*, *Add a button*, *On a timer*. Each has a task, a hint, **Check it** and **Show me a way**. Passing
them counts toward the *Script Learner* badge.

## A first script

```js
// Greets new members and answers !hello
on('join', e => post('general', `Welcome, ${e.member.name}!`));

command('hello', e => reply(`Hello ${e.member.name}, you are member number ${members.count()}.`));
```

The top level only registers **handlers** (`on`, `command`, `every`, `at`, `widget`, `button`…). Everything else
happens inside them. See the [Script reference](reference.md).

## Powers

A script may use only what its code names when it's saved: posting, reading chat, members, flair, data, design, live
news, cards, connections, webhooks and so on. Officers see each script's **powers**, and the officers' log names new
ones when a script changes. Any other call is refused.

## Limits

Each run has up to **300 ms**, **250,000 statements** and **24 MB** (double in a private group: the owner's
setting, any number of members). While a private group's owner has the GC client open, its scripts run on their PC with
ten times these limits; otherwise on Games Communities' servers. Scripts have no network, files or timers of their own: they use the calls Games Communities gives
them. The editor shows each run's cost, red from 75% of the limit.

Games Communities' staff can stop a script that misbehaves; officers see why.

## Other languages

- **Luau**: the same API by the same names; tables for objects, arrays from 1, `nil` for null.
  ```lua
  on("join", function(e) post("general", "Hi " .. e.member.name) end)
  command("win", function(e) reply(`Wins: {memberData.add(e.member.id, "wins", 1)}`) end)
  ```
- **Python** and **WebAssembly**: pick them as the new script's language; they run in the same sandbox with the same
  calls.
- **Blueprints**: events, actions and values as boxes joined by wires, for officers who don't code.
