> For the complete documentation index, see [llms.txt](https://sbscripts.gitbook.io/sb-scripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sbscripts.gitbook.io/sb-scripts/sb-minigames/using-an-export.md).

# Using an Export

Exports are **client side only**. The pattern is always the same:

```lua
exports['sbminigames']:GameName(options, function(success)
    -- success is true or false
end)
```

### Three ways to call it

**1. Options table and callback** (recommended, every option is named):

```lua
exports['sbminigames']:StopBar({ speed = 220, zones = 4 }, function(success)
    print(success)
 end)
```

**2. Positional arguments and callback** (shorter, order is fixed per game):

```lua
exports['sbminigames']:Circle('hard', 3, function(success)
    print(success)
end)
```

Use `nil` to skip an argument and take its default: `exports['sbminigames']:Keypad(nil, 500, 25, cb)`.

**3. Callback only** (everything from `shared/config.lua`):

```lua
exports['sbminigames']:Quickdraw(function(success)
    print(success)
end)
```

### Waiting for the result

If you leave the callback out, the export waits and returns the result. Only do this inside a thread, such as `CreateThread`, a command or an event handler. Never use it at the top level of a script.

```lua
CreateThread(function()
    local success = exports['sbminigames']:Mash({ key = 'E', presses = 25 })
    if success then print('done') end
end)
```

### Results

| Value   | Meaning                                             |
| ------- | --------------------------------------------------- |
| `true`  | The player passed.                                  |
| `false` | The player failed, ran out of time, or pressed ESC. |

ESC always cancels the game and returns `false`. Your code can't tell a cancel from a failure, which is intended.

### One game at a time

If a game is already open, a new call is ignored. The export returns `false`, and your callback is **not** called. Check first:

```lua
if not exports['sbminigames']:IsOpen() then
    exports['sbminigames']:Wires({ pairs = 4 }, cb)
end
```

| Export     | Returns | What it does                                                            |
| ---------- | ------- | ----------------------------------------------------------------------- |
| `IsOpen()` | boolean | `true` while a game is on screen.                                       |
| `Cancel()` | boolean | Closes the open game as a failure. Returns `false` if nothing was open. |

### Option rules

* Values outside the allowed range are clamped, not rejected. For example, `{ circles = 99 }` becomes `6`.
* Wrong types are replaced by the default from `shared/config.lua`.
* A `time` of `0` means no time limit, where the game allows it. Games with a mandatory timer have a minimum, listed in their tables.
