Skip to content

@minecraft/server-ui


@minecraft/server-ui / ObservableString

Class: ObservableString

Defined in: @minecraft/server-ui/index.d.ts:1331

An observable that holds a string value. Listeners are notified whenever the value changes.

Constructors

Constructor

new ObservableString(data, options?): ObservableString

Defined in: @minecraft/server-ui/index.d.ts:1347

Parameters

data

string

The initial string value for this observable.

options?

ObservableOptions

Optional configuration for the observable, such as whether the value can be written by the client.

Returns

ObservableString

Remarks

Creates a new ObservableString with the provided initial string value.

This function can't be called in restricted-execution mode.

This function can be called in early-execution mode.

Methods

getData()

getData(): string

Defined in: @minecraft/server-ui/index.d.ts:1357

Returns

string

Remarks

Returns the current string value held by this observable.

This function can't be called in restricted-execution mode.

This function can be called in early-execution mode.


getFilteredText()

getFilteredText(player): Promise<string | TextFilteringError[]>

Defined in: @minecraft/server-ui/index.d.ts:1376

Parameters

player

Player

Returns

Promise<string | TextFilteringError[]>

Remarks

Gets filtered data from the Observable (only available for strings). In case of failure, it will return an array of TextFilteringError that can provide more context about the filtering process. For testing purposes, the options are available under 'Creator -> Text Filtering' settings menu. This delay is only applied to the getFilteredText function and can be used to simulate network latency when testing.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

minecraftcommon.EngineError

minecraftserver.InvalidEntityError


setData()

setData(data): void

Defined in: @minecraft/server-ui/index.d.ts:1390

Parameters

data

string

The new string value to set.

Returns

void

Remarks

Updates the string value held by this observable. If the new value differs from the current value, all subscribed listeners are notified with the new value.

This function can't be called in restricted-execution mode.

This function can be called in early-execution mode.


subscribe()

subscribe(callback): (arg0) => void

Defined in: @minecraft/server-ui/index.d.ts:1405

Parameters

callback

(arg0) => void

A function that receives the new string value each time the observable changes.

Returns

(arg0) => void

Remarks

Registers a callback to be invoked whenever the observable's value changes. Returns the callback, which can be passed to unsubscribe to remove the listener.

This function can't be called in restricted-execution mode.

This function can be called in early-execution mode.


unsubscribe()

unsubscribe(callback): boolean

Defined in: @minecraft/server-ui/index.d.ts:1419

Parameters

callback

(arg0) => void

The callback handle previously returned by subscribe.

Returns

boolean

Remarks

Removes a previously registered listener from this observable. Returns true if the listener was found and removed, false if it was not found.

This function can't be called in restricted-execution mode.

This function can be called in early-execution mode.