> ## Documentation Index
> Fetch the complete documentation index at: https://lationscripts.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Modern UI - Pattern Lock

> Memory-based sequence minigame with preset or custom difficulty and multi-stage support

Pattern Lock is a memory minigame where the UI plays a dot sequence on a grid and the player must repeat it in the same order before time runs out. Supports preset difficulties, custom configs, and multi-stage progressions.

## Quick Start

```lua theme={null}
local success = exports.lation_ui:patternLock('Bypass Panel', 'medium')

if success then
    print('Success')
else
    print('Failed')
end
```

## Functions

<AccordionGroup>
  <Accordion title="patternLock" icon="grid-2">
    Start a pattern lock minigame and wait for the result.

    ```lua theme={null}
    local success = exports.lation_ui:patternLock(title, difficulty)
    ```

    **Parameters:**

    * `title` (string, optional) - Title displayed in the header (default: `'Pattern Lock'`)
    * `difficulty` (string | table, optional) - Difficulty preset, custom config object, or array for multi-stage (default: `'medium'`)

    **Returns:**

    * `success` (boolean) - `true` if all stages were completed successfully, `false` if failed, timed out, or cancelled
  </Accordion>

  <Accordion title="cancelPatternLock" icon="xmark">
    Cancel the currently active pattern lock.

    ```lua theme={null}
    exports.lation_ui:cancelPatternLock()
    ```

    <Note>
      Throws an error if no pattern lock is active.
    </Note>
  </Accordion>

  <Accordion title="patternLockActive" icon="circle-question">
    Check if a pattern lock is currently active.

    ```lua theme={null}
    local isActive = exports.lation_ui:patternLockActive()
    ```

    **Returns:**

    * `isActive` (boolean) - `true` if a pattern lock is active, `false` otherwise
  </Accordion>
</AccordionGroup>

## Configuration

### Options

<ParamField path="title" type="string">
  Title displayed in the panel header
</ParamField>

<ParamField path="difficulty" default="medium" type="string | table">
  Difficulty preset, custom difficulty object, or array of presets/objects for multi-stage runs

  See [Difficulty Levels](#difficulty-levels) for available options

  <Note>
    Multi-stage runs display a **Stage** badge in the header (e.g. `Stage 1`, `Stage 2`). The player must complete every stage to return `true`.
  </Note>
</ParamField>

### Difficulty Levels

<Tabs>
  <Tab title="Preset Difficulties">
    Use predefined difficulty levels for quick setup.

    <ParamField path="easy" type="string">
      3x3 grid, 3-dot sequence, 700ms per dot, 10s input timeout
    </ParamField>

    <ParamField path="medium" type="string">
      3x3 grid, 5-dot sequence, 500ms per dot, 12s input timeout
    </ParamField>

    <ParamField path="hard" type="string">
      4x4 grid, 7-dot sequence, 350ms per dot, 14s input timeout
    </ParamField>

    **Example:**

    ```lua theme={null}
    local success = exports.lation_ui:patternLock('Bypass Panel', 'medium')
    ```

    **Multi-stage example:**

    ```lua theme={null}
    local success = exports.lation_ui:patternLock('Thermite Prep', { 'easy', 'medium', 'hard' })
    ```
  </Tab>

  <Tab title="Custom Difficulty">
    Create custom difficulty configurations with precise control.

    <ParamField path="gridSize" type="number">
      Grid dimension (3-5)
    </ParamField>

    <ParamField path="sequenceLength" type="number">
      Number of dots in the sequence (2-12)
    </ParamField>

    <ParamField path="showSpeed" type="number">
      Milliseconds each dot stays lit during playback (150-1500)
    </ParamField>

    <ParamField path="inputTimeout" type="number">
      Seconds allowed to repeat the pattern (5-30)
    </ParamField>

    **Example:**

    ```lua theme={null}
    local success = exports.lation_ui:patternLock('Security Grid', {
        gridSize = 4,
        sequenceLength = 6,
        showSpeed = 400,
        inputTimeout = 15
    })
    ```
  </Tab>
</Tabs>

## Behavior

* The same dot **can** appear more than once in a sequence, but **never twice in a row**
* Pressing **Escape** fails the minigame
* While active, the minigame captures full NUI focus (cursor + keyboard)

## Preview

<Frame>
  <img src="https://mintcdn.com/lationscripts/Ti0acW9JT3q4BC3Y/resources/modern-ui/components/pattern-lock/example.webp?fit=max&auto=format&n=Ti0acW9JT3q4BC3Y&q=85&s=f6c65fef9eca7e3c16c4897bf01dea8e" alt="Pattern Lock Example" width="604" height="792" data-path="resources/modern-ui/components/pattern-lock/example.webp" />
</Frame>
