[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / [command/function/runtime](https://jsprismarine.dev/api/@jsprismarine/prismarine/command/function/runtime/index.md) / FunctionRuntime

# Class: FunctionRuntime

Defined in: [packages/prismarine/src/command/function/runtime.ts:82](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L82)

Runs functions, and remembers the ones `/schedule` put off until later.

Built once per content build, because the compiled functions it runs are.
A reload replaces it rather than mutating it, which also drops whatever was
scheduled against the functions that no longer exist.

## Constructors

### Constructor

> **new FunctionRuntime**(`options`): `FunctionRuntime`

Defined in: [packages/prismarine/src/command/function/runtime.ts:104](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L104)

#### Parameters

##### options

[`FunctionRuntimeOptions`](https://jsprismarine.dev/api/@jsprismarine/prismarine/command/function/runtime/index.md#functionruntimeoptions)

#### Returns

`FunctionRuntime`

## Accessors

### queued

#### Get Signature

> **get** **queued**(): `number`

Defined in: [packages/prismarine/src/command/function/runtime.ts:225](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L225)

How many calls are waiting on the schedule.

##### Returns

`number`

***

### size

#### Get Signature

> **get** **size**(): `number`

Defined in: [packages/prismarine/src/command/function/runtime.ts:134](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L134)

How many functions the stack registered.

##### Returns

`number`

## Methods

### clearQueue()

> **clearQueue**(`reference`): `number`

Defined in: [packages/prismarine/src/command/function/runtime.ts:220](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L220)

Drops every pending call of one reference.

#### Parameters

##### reference

`string`

#### Returns

`number`

How many were dropped.

***

### has()

> **has**(`reference`): `boolean`

Defined in: [packages/prismarine/src/command/function/runtime.ts:149](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L149)

Whether a reference names something that exists: a function, or a declared tag.

#### Parameters

##### reference

`string`

#### Returns

`boolean`

***

### ids()

> **ids**(): readonly `string`[]

Defined in: [packages/prismarine/src/command/function/runtime.ts:139](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L139)

Every function id the stack registered.

#### Returns

readonly `string`[]

***

### queue()

> **queue**(`reference`, `delayTicks`, `mode`): `boolean`

Defined in: [packages/prismarine/src/command/function/runtime.ts:210](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L210)

Queues a function for later.

#### Parameters

##### reference

`string`

##### delayTicks

`number`

##### mode

[`ScheduleMode`](https://jsprismarine.dev/api/@jsprismarine/prismarine/command/function/schedule/index.md#schedulemode)

#### Returns

`boolean`

True always, matching Java: a `/schedule` of a function that
  does not exist yet is legal, because a later pack reload may provide
  it before the call comes due.

***

### requestReturn()

> **requestReturn**(`value`): `number`

Defined in: [packages/prismarine/src/command/function/runtime.ts:240](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L240)

Records a `/return`, which ends the function the running line belongs
to.

#### Parameters

##### value

`number` \| `undefined`

What the function returns, or undefined for the two
  forms that end it without a value.

#### Returns

`number`

What the `/return` line itself reports.

#### Throws

When no function is running. Java refuses a `/return`
  typed at a console the same way, and the dispatcher turns this into
  the message the sender sees.

***

### run()

> **run**(`reference`, `source`, `argumentText?`, `stored?`): [`FunctionRunOutcome`](https://jsprismarine.dev/api/@jsprismarine/prismarine/command/function/runtime/index.md#functionrunoutcome)

Defined in: [packages/prismarine/src/command/function/runtime.ts:167](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L167)

Runs one function or one function tag.

#### Parameters

##### reference

`string`

A function id, or a tag written `#namespace:tag`.

##### source

[`CommandSource`](https://jsprismarine.dev/api/@jsprismarine/commands/index.md#commandsource)

What `/function` was typed with. Every line runs with it
  made silent, as Java runs a function's output.

##### argumentText?

`string`

The macro argument compound, as SNBT.

##### stored?

`boolean` = `false`

Whether the compound is a stored one printed back, as `/function … with`
  passes it, so a printed non-finite number reads back as one.

#### Returns

[`FunctionRunOutcome`](https://jsprismarine.dev/api/@jsprismarine/prismarine/command/function/runtime/index.md#functionrunoutcome)

What `/function` reports and whether `execute if function`
  matches. A function that does not exist ran nothing and matched
  nothing.

***

### runLoad()

> **runLoad**(`source`): `number`

Defined in: [packages/prismarine/src/command/function/runtime.ts:252](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L252)

Runs `#minecraft:load`, which a server does once after its packs load.

#### Parameters

##### source

[`CommandSource`](https://jsprismarine.dev/api/@jsprismarine/commands/index.md#commandsource)

#### Returns

`number`

How many command lines ran.

***

### tagIds()

> **tagIds**(): readonly `string`[]

Defined in: [packages/prismarine/src/command/function/runtime.ts:144](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L144)

Every function tag id the stack declares.

#### Returns

readonly `string`[]

***

### tick()

> **tick**(`source`): `number`

Defined in: [packages/prismarine/src/command/function/runtime.ts:267](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/function/runtime.ts#L267)

One server tick: whatever `/schedule` put on this tick, then
`#minecraft:tick`.

Schedules first, which is Java's order. Both are skipped outright when
nothing is waiting and no pack declared the tag, so a server with no
datapack pays a map lookup per tick and nothing else.

#### Parameters

##### source

[`CommandSource`](https://jsprismarine.dev/api/@jsprismarine/commands/index.md#commandsource)

#### Returns

`number`

How many command lines ran across everything this tick.
