Skip to main content

Client API

Every export below is client-side and lives in API.lua inside the resource. That file is in escrow_ignore, so you can read the source of anything on this page.

Headset

isRoadVrActive

Is the headset currently on?
boolean
true while the player is wearing it.

getRoadVrState

The state machine, as a string.
string
One of off, booting, passthrough, focus, shutdown.passthrough is windows floating while the player moves normally. focus is the mode in which the mouse is free and the player can click.

putVisorOn

Puts the visor on another ped’s head.
number
required
The ped handle to fit the visor to.
table | nil
A handle you keep for takeVisorOff. nil when nothing was possible on that ped.
This exists for scene work — actors who should be wearing the headset without the calling resource having to know anything about head bones, offsets or addon clothing. It does not start a session for that ped.

takeVisorOff

table
required
The handle putVisorOn returned.

Panels

openRoadVrPanel

Opens a window for a registered app.
string
required
A registered app id — one of RoadVR’s own, or one you registered yourself.
table
string | nil
nil when the headset is off.

closeRoadVrPanel

string
required
The id openRoadVrPanel returned.

Custom apps

Full guide with a working example: Custom Apps.

registerRoadVrApp

table
required
boolean
false when the id already belongs to another resource.
string
Why it failed.

unregisterRoadVrApp

Not needed on resource stop — that is cleaned up on its own.

sendToRoadVrApp

Sends data into your app’s window. It arrives as a message event carrying { source: 'roadvr', ...payload }.
boolean
false while the window is closed — normal, not an error. Your resource has no idea whether the player has your app open.

Custom widgets

Full guide with a working example: Custom Widgets.

registerRoadVrWidget

table
required

unregisterRoadVrWidget

Widgets already hanging are left on the wall. They are in the player’s profile, and a resource going away is not a reason to clear somebody’s room — they fall back to an unavailable plate until it returns.

sendToRoadVrWidget

Reaches every widget of this kind that is currently drawn. Arrives as { source: 'roadvr', widget: '<id>', ...payload }.
boolean
false when the kind is not yours.

getRoadVrWidgetInstances

Which widgets of your kind are on a wall right now.
table
A list of instance ids. An empty table is a normal answer — the player may simply not have hung one.

Talking to a page from inside the frame

Everything above is Lua. The other half — a page asking RoadVR about the theme, its window, or the fact that it is closing — is the JavaScript SDK.

JavaScript SDK

ready(), the context object, the events, applyTheme(), watch(), setActions() and close()