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

# Code Console

> Embedded console for running controlled n3 command scripts.

# n3 Code Console

The n3 Code Console is a disabled-by-default, hidden developer plugin that runs small, controlled n3 command scripts from a Swing panel. It avoids compiling or executing arbitrary Java, shell commands, or persisted scripts.

## Enablement

* Plugin entrypoint: `com.n3plugins.codeconsole.CodeConsolePlugin`
* RuneLite panel tooltip: `n3 Code Console`
* Bundle registration: `runelite-plugin.properties`
* Descriptor: `hidden = true` (session/developer console, excluded from default user plugin list unless enabled via internal/hidden plugin configurations)

The side panel opens from the RuneLite toolbar after the plugin starts.

## UI Controls

* `Commands`: session-only script editor.
* `Output`: structured status and command result log.
* `Run`: parses the entire editor first, then queues the script if it is valid.
* `Stop`: requests a safe stop. The active script stops on the next console tick.
* `Clear`: clears output text only.
* `Ctrl+Enter`: same as `Run`.
* `Status`: shows idle, queued, running, stopping, or parse-error state.

Command text, output, and history persist in-memory only for v1. The plugin saves nothing to disk. The output limit is 500 lines, and command history retains 25 scripts.

## Script Rules

* One command per line.
* The parser ignores blank lines.
* `#` starts a comment unless it appears inside quotes.
* Use double quotes for multi-word arguments.
* Item and NPC targets accept names or numeric IDs where the command supports both.
* Boolean arguments accept `true`, `false`, `noted`, `item`, `on`, and `off` where noted/item mode applies.
* The parser validates the full script before executing commands.
* Unknown commands, wrong argument counts, unclosed quotes, and invalid numbers stop the script from queueing.

Example:

```text theme={null}
## quick bank and player-state check
bank.isOpen
bank.count coins
state.location
wait 2
npc.interact "Grand Exchange Clerk" Talk-to
```

## Execution Model

The executor runs one script at a time from RuneLite game ticks. Run and Stop button events schedule executor state changes through `ClientThreadBridge.invokeLater`, keeping executor mutation on the client-thread path with tick execution. Each command returns a `StepResult`:

* `SUCCESS`: log the result and advance to the next command.
* `WAIT`: delay by the requested number of ticks, then continue.
* `RETRY`: retry the same command up to the bounded retry limit.
* `FAILED`: stop the script and log the failure.
* `RESET`: return to the first command.

Game-client reads and actions route through existing client-thread-safe project APIs, primarily `ClientThreadBridge` and result-aware `Api.actions` wrappers.

## Commands

Command names ignore case. The console passes names and actions to the existing interaction APIs, so exact available actions depend on the current widget, item, NPC, and RuneLite state.

### Bank

```text theme={null}
bank.isOpen
bank.count <item-id-or-name>
bank.depositInventory
bank.depositEquipment
bank.setNoted <true|false|noted|item|on|off>
bank.withdraw <item-id-or-name> <amount> [true|false|noted|item|on|off]
```

Examples:

```text theme={null}
bank.isOpen
bank.count 995
bank.count coins
bank.setNoted noted
bank.withdraw "Law rune" 50
bank.withdraw 385 10 item
bank.depositInventory
```

The command enforces the optional third `bank.withdraw` argument per call. `noted`, `true`, and `on` switch to noted mode before withdrawing; `item`, `false`, and `off` switch back to item mode before withdrawing.

### Inventory

```text theme={null}
inv.list
inv.count <item-id-or-name>
inv.use <item-id-or-name> <action> [additional-actions...]
```

Examples:

```text theme={null}
inv.list
inv.count lobster
inv.use lobster Eat
inv.use "Teleport to house" Break
```

### NPC

```text theme={null}
npc.interact <npc-id-or-name> <action> [additional-actions...]
```

Examples:

```text theme={null}
npc.interact Banker Bank
npc.interact "Grand Exchange Clerk" Talk-to
```

### Object

```text theme={null}
object.interact <object-id-or-name> <action> [additional-actions...]
```

Examples:

```text theme={null}
object.interact "Bank booth" Bank
object.interact Door Open
object.interact 10355 Mine
```

### Tile Item

```text theme={null}
tileitem.interact <item-id-or-name> <action> [additional-actions...]
```

Examples:

```text theme={null}
tileitem.interact Bones Take
tileitem.interact 385 Take
```

### Prayer

`inv.use` requires the Inventory tab to be visible, and `prayer.set` requires the Prayer tab when a state change is needed. The console propagates `WIDGET_HIDDEN`; it does not select tabs automatically. Open the required tab in the client before running the dependent line.

```text theme={null}
prayer.set <prayer-name> <on|off|true|false>
```

Examples:

```text theme={null}
prayer.set Piety on
prayer.set Protect_from_Melee off
prayer.set "Protect from Magic" true
```

### Walk

```text theme={null}
walk <x> <y> [plane]
```

Examples:

```text theme={null}
walk 3200 3201
walk 3218 3218 0
```

### State And Vars

```text theme={null}
state.location
state.tick
varbit <id>
varp <id>
```

Examples:

```text theme={null}
state.location
state.tick
varbit 3960
varp 281
```

### Flow Control

```text theme={null}
wait <ticks>
stop
```

Examples:

```text theme={null}
wait 3
stop
```

## Safety Boundaries

The v1 console excludes:

* arbitrary Java evaluation
* dynamic compilation
* shell execution
* global `System.out` / `System.err` redirection
* unsafe thread stopping
* saved script files

Add new command surfaces by extending `CodeConsoleCommandAdapter`, `DefaultCodeConsoleCommandAdapter`, and `CodeConsoleParser`. Then test parser dispatch and executor behavior under `src/test/java/com/n3plugins/codeconsole`.

## Verification

After changing the console, run:

```powershell theme={null}
.\gradlew.bat test --tests com.n3plugins.codeconsole.* --console plain
.\gradlew.bat test --console plain
.\gradlew.bat FatJar --console plain
```

The fat jar includes `com/n3plugins/codeconsole/CodeConsolePlugin.class`, and `runelite-plugin.properties` lists `com.n3plugins.codeconsole.CodeConsolePlugin`.
