> For the complete documentation index, see [llms.txt](https://barcode.gitbook.io/ps5-controller/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://barcode.gitbook.io/ps5-controller/documentation.md).

# Documentation

## Custom Scripting Language - PS5 Controller

***

### 1. Buttons and Controls

* **Buttons**: `buttonX`, `buttonCircle`, `buttonSquare`, `buttonTriangle`, `L1`, `L2`, `R1`, `R2`, `L3`, `R3`, `DPadUp`, `DPadDown`, `DPadLeft`, `DPadRight`, `PSButton`, `Touchpad`, `Options`
* **Analog Sticks**: `LeftStick`, `RightStick`

### 2. Binds

Defines mappings of controller inputs to actions with specific trigger types. All binds include the input and the action to be executed.

#### Examples:

* **Single Button Press**:

  ```plaintext
  bind onPress(buttonX) to jump               # Executes the 'jump' action when buttonX is pressed
  ```
* **Button Release**:

  ```plaintext
  bind onRelease(buttonO) to crouch           # Executes the 'crouch' action when buttonO is released
  ```
* **Holding Multiple Buttons**:

  ```plaintext
  bind onHold(L1 + R2) to rapidFire           # Executes the 'rapidFire' action when L1 and R2 are held together
  ```
* **Double Press**:

  ```plaintext
  bind onDoublePress(buttonSquare) to quickReload    # Executes the 'quickReload' action when buttonSquare is double-pressed
  ```
* **Combo of Buttons**:

  ```plaintext
  bind onCombo(L1 + buttonCircle) to activateShield  # Executes the 'activateShield' action when L1 and buttonCircle are pressed in sequence
  ```

### 3. Actions

Defines what happens when an action is called. Actions can include commands like pressing or releasing buttons, waiting, enabling/disabling loops, and more. Actions should not redundantly perform user-triggered tasks.

#### Examples:

```plaintext
action jump:
    press(buttonX)                                # Presses buttonX to initiate a jump
    wait(100ms)                                   # Waits for 100 milliseconds to simulate jump duration
    log("Jump executed!")                         # Logs a message
end

action quickReload:
    press(buttonSquare)                           # Presses buttonSquare to reload
    wait(300ms)                                   # Waits for reload duration
    log("Quick reload executed!")
end

action activateShield:
    press(L1)                                     # Presses L1 to activate the shield
    wait(200ms)
    log("Shield activated!")
end

action rapidFire:
    enableLoop                                    # Enables a loop for continuous fire
    loop rapidFireLoop every 50ms:
        press(R2)
        wait(50ms)
    end
    log("Rapid fire activated!")
end
```

### 4. Triggers

Defines event-based conditions to detect when a bind occurs and executes a corresponding action.

#### Examples:

```plaintext
trigger onBindDetected(quickReload) call quickReload                    # Calls 'quickReload' when the bind is detected
trigger onTimeElapsed(3s) call coolDown                                 # Calls 'coolDown' action after 3 seconds have passed
trigger onSequenceDetected(defenseCombo) call defenseMode               # Calls 'defenseMode' when a combo sequence named 'defenseCombo' is detected
trigger onLoopCompleted(rapidFire, rapidFireLoop) call stopRapidFire    # Calls 'stopRapidFire' when 'rapidFireLoop' within 'rapidFire' completes
```

### 5. Loops

Loops allow actions to be executed repeatedly for automated sequences or for a defined number of iterations.

#### Examples:

* **Basic Loop with Timing**:

  ```plaintext
  loop rapidFire every 50ms:                  # Executes commands within the loop every 50ms
      press(R2)
      wait(50ms)
  end
  ```
* **Loop with Fixed Iterations**:

  ```plaintext
  loop repeatAttack repeat(3):                  # Executes the loop 3 times to simulate a triple attack
      press(buttonX)
      wait(200ms)
  end
  ```
* **Using Break and Continue**:

  ```plaintext
  loop defenseMode every 100ms:
      if(onPress(buttonO)):                   # If buttonCircle is pressed
          continue                            # Skips this iteration of the defense mode loop
      press(buttonSquare)                     # Executes defense action
      wait(100ms)
  end
  ```

### 6. Conditions

Defines conditional checks based on the state of controls and button combinations. Conditions should focus on logical input scenarios rather than real-time inputs like pressure or stick movements.

#### Examples:

```plaintext
if(onPress(buttonX) and onHold(L1)) then call specialMove       # Calls 'specialMove' if buttonX is pressed and L1 is held
if(onRelease(buttonR2) and onPress(buttonCircle)) then call evadeAttack # Calls 'evadeAttack' if R2 is released and Circle is pressed
```

### 7. Comprehensive Example

#### Binds

```plaintext
bind onPress(buttonX) to jump
bind onRelease(L1) to stopAiming
bind onHold(L1 + R2) to rapidFire
bind onDoublePress(buttonSquare) to quickReload
bind onCombo(L1 + buttonCircle) to activateShield
```

#### Actions

```plaintext
action jump:
    press(buttonX)
    wait(100ms)
    log("Jump executed!")
end

action quickReload:
    press(buttonSquare)
    wait(300ms)
    log("Quick reload executed!")
end

action rapidFire:
    enableLoop
    loop rapidFire every 50ms:
        press(R2)
        wait(50ms)
    end
    log("Rapid fire activated!")
end
```

#### Triggers

```plaintext
trigger onBindDetected(jump) call jump                            # Calls 'jump' action when the 'jump' bind is detected
trigger onTimeElapsed(2s) call autoCover                          # Calls 'autoCover' action after 2 seconds have passed
trigger onLoopCompleted(rapidFire, rapidFireLoop) call stopRapidFire # Calls 'stopRapidFire' when the 'rapidFireLoop' within 'rapidFire' completes
```
