Skip to main content

Player

OBR.player

The player API gives you access to the current player using Owlbear Rodeo.

Reference

Properties

NAMETYPEDESCRIPTION
idstringThe user ID for this player. This will be shared if the same player joins a room multiple times

Methods

getSelection

async getSelection()

Get the current selection for this player.

Returns an array of Item IDs or undefined if the player has no current selection.


select

async select(items, replace?)

Select items for the player.

Parameters

NAMETYPEDESCRIPTION
itemsstring[]An array of item IDs to select
replacebooleanAn optional boolean, if true the users selection will be replaced, if false the selection will be combined with their current selection

deselect

async deselect(items)

Deselect a set of items or all items.

Parameters

NAMETYPEDESCRIPTION
itemsstring[]An optional array if item IDs to deselect, if undefined all items will be deselected

getName

async getName()

Get the name for this player.

Returns a string.


setName

async setName(name)

Parameters

NAMETYPEDESCRIPTION
namestringThe new name for this player

getColor

async getColor()

Get the color for this player.

Returns a string.


setColor

async setColor(color)

Parameters

NAMETYPEDESCRIPTION
colorstringThe new color for this player

getSyncView

async getSyncView()

Get whether this player currently has sync view enabled

Returns a boolean.


setSyncView

async setSyncView(syncView)

Parameters

NAMETYPEDESCRIPTION
syncViewbooleanThe new sync view state for this player

getId

async getId()

Get the user ID for this player. In most cases the id property should be used instead as it is synchronous.

This will be shared if the same player joins a room multiple times.

Returns a string.


getRole

async getRole()

Get the current role for this player.

returns "GM" | "PLAYER".


getMetadata

async getMetadata()

Get the current metadata for this player.

returns a Metadata object.


setMetadata

async setMetadata(update)

Update the metadata for this player.

See Metadata for best practices when updating metadata.

Parameters

NAMETYPEDESCRIPTION
updatePartial<Metadata>A partial update to this players metadata. The included values will be spread among the current metadata to avoid overriding other values.

hasPermission

async hasPermission(permission)

Does this player have the given permission.

Parameters

NAMETYPEDESCRIPTION
permissionPermissionThe permission to check

Returns a boolean.


getConnectionId

async getConnectionId()

Get the current connection ID for this player.

This will be unique if the same player joins the room multiple times.

Returns a string.


onChange

onChange(callback);

Parameters

NAMETYPEDESCRIPTION
callback(player: Player) => voidA callback for when a value on the current player changes

Returns a function that when called will unsubscribe from change events.

Example

/**
* Use an `onChange` event with a React `useEffect`.
* `onChange` returns an unsubscribe event to make this easy.
*/
useEffect(
() =>
OBR.player.onChange((player) => {
// React to player changes
}),
[]
);