Skip to main content

Code Console DSL Examples

This page is a practical guide for writing short n3 Code Console scripts. The DSL is intentionally small: each line is one command, arguments are separated by spaces, and quoted text keeps multi-word names together.

Use the Code Console command reference when you need the full command list.

Writing A Script

Start with a goal, then write one safe action or read-only check per line.

# comments are ignored
state.location
bank.isOpen
wait 2
state.tick

The console parses every line before it runs anything. If one line is invalid, the script will not queue. Run and Stop are scheduled onto the client-thread path before executor state changes.

Argument Rules

Single-word item or NPC names do not need quotes:

inv.count lobster
npc.interact Banker Bank

Use double quotes for names or actions containing spaces:

bank.count "Law rune"
npc.interact "Grand Exchange Clerk" Talk-to
inv.use "Teleport to house" Break

IDs can be used anywhere an item or NPC target is accepted:

bank.count 995
inv.count 385
npc.interact 1613 Attack

Comments can sit at the end of a line:

state.tick # prints the current client tick

Read-Only Debug Recipes

Current Location And Tick

Use this when checking whether the client is available and where the player is standing.

state.location
state.tick

Expected output includes the world location as x,y,plane and the current tick count.

Bank And Inventory Snapshot

Use this before testing bank or inventory actions.

bank.isOpen
bank.count coins
inv.list

If the bank is closed, bank.count returns the safe current count result from the bank action layer and does not try to open the bank.

Var Debug Check

Use this to inspect known varbit or varp IDs while reproducing UI or game-state behavior.

varbit 3960
varp 281

The DSL only reads vars. It does not write varbits or varps.

Bank Recipes

Deposit Inventory

Only run this while the bank is open.

bank.isOpen
bank.depositInventory
wait 1
inv.list

The wait 1 gives the client one game tick before reading inventory again.

Deposit Equipment

Only run this while the bank is open.

bank.isOpen
bank.depositEquipment

Withdraw Items

Withdraw by item name:

bank.isOpen
bank.withdraw lobster 10
wait 1
inv.count lobster

Withdraw by item ID:

bank.isOpen
bank.withdraw 995 1000
wait 1
inv.count 995

Withdraw Noted Items

The third bank.withdraw argument controls noted mode for that withdraw command.

bank.isOpen
bank.withdraw "Law rune" 50 noted

Equivalent accepted boolean forms:

bank.withdraw "Law rune" 50 true
bank.withdraw "Law rune" 50 on
bank.withdraw "Law rune" 50 noted

Use item, false, or off for item mode:

bank.withdraw lobster 10 item

The mode argument is enforced for each withdraw. A previous noted-mode command will not make a later item withdraw come out as notes.

Set Bank Withdraw Mode

Use this when you want the bank mode changed before later manual or scripted actions.

bank.setNoted noted
bank.setNoted item

Inventory Recipes

List Inventory

inv.list

The output includes item names, quantities, and item IDs.

Count Food

inv.count lobster
inv.count 385

Name matching is exact and case-insensitive in the current adapter path. If a name does not match, use the item ID.

Use An Inventory Item

inv.use lobster Eat
wait 1
inv.count lobster

Use a multi-word item:

inv.use "Teleport to house" Break

Use an action fallback list:

inv.use "Ring of dueling(8)" "Castle Wars" Rub

The action wrapper decides which action is available. Unsupported actions fail with a structured result.

NPC Recipes

Talk To An NPC

npc.interact Banker Talk-to

Bank With A Banker

npc.interact Banker Bank
wait 2
bank.isOpen

Interact With A Multi-Word NPC Name

npc.interact "Grand Exchange Clerk" Talk-to

Attack By NPC ID

npc.interact 1613 Attack

Prefer names for readability unless multiple NPCs share the same name and the ID matters.

Object Recipes

Mine An Ore

object.interact 11364 Mine # Mine iron ore by ID
wait 3

Open A Door By Name

object.interact Door Open

Use Bank Booth

object.interact "Bank booth" Bank
wait 2
bank.isOpen

Tile Item Recipes

Take Ground Item

tileitem.interact Bones Take

Take Ground Item By ID

tileitem.interact 526 Take

Prayer Recipes

Turn On Melee Protection

prayer.set Protect_from_Melee on

Turn Off Magic Protection

prayer.set "Protect from Magic" off

Walk Recipes

Walk to Coordinates

walk 3200 3201

Walk to Specific Plane

walk 3218 3218 0

Flow Control Recipes

Wait Between Actions

Use wait after an interaction when the client needs time to update widgets, inventory, or position.

inv.use lobster Eat
wait 1
inv.count lobster

Stop A Script Early

stop is useful while building examples or temporarily disabling the lower half of a script.

state.location
stop
bank.depositInventory

The command after stop will not run.

Common Parse Errors

Missing Quotes

Bad:

bank.count Law rune

Good:

bank.count "Law rune"

Missing Action

Bad:

inv.use lobster

Good:

inv.use lobster Eat

Invalid Number

Bad:

wait two
bank.withdraw coins 0

Good:

wait 2
bank.withdraw coins 100

Unknown Command

Bad:

bank.open

Good for v1:

npc.interact Banker Bank
wait 2
bank.isOpen

Full Example Scripts

Safe Startup Check

# confirm basic client state
state.location
state.tick
inv.list
bank.isOpen

Banker Open And Inventory Check

npc.interact Banker Bank
wait 2
bank.isOpen
bank.count coins
inv.list

Withdraw Food Then Confirm

bank.isOpen
bank.withdraw lobster 10 item
wait 1
inv.count lobster

Deposit Inventory Then Confirm Empty Slots Visually

bank.isOpen
bank.depositInventory
wait 1
inv.list

Eat One Food And Check Count

inv.count lobster
inv.use lobster Eat
wait 1
inv.count lobster

Extending The DSL

When adding new commands, keep the command name explicit and namespace-like:

object.interact Door Open
tileitem.take "Bones"
prayer.set Protect_from_Melee on

Implementation checklist:

  • Add parser handling in CodeConsoleParser.
  • Add a method to CodeConsoleCommandAdapter.
  • Implement the live behavior in DefaultCodeConsoleCommandAdapter.
  • Route client actions through existing client-thread-safe APIs.
  • Add parser dispatch, executor, panel-buffer, and client-thread scheduling tests under src/test/java/com/n3plugins/codeconsole.