Build & Create

Code that shapes worlds

For builders: write small scripts that make your map react to people, remember things, and show its own buttons and windows.

WA.ui, WA.room, WA.player, WA.state — the scripting API from WorkAdventure. Control rooms, players, state, and UI from your map scripts.

What a script can reach

Four main parts, and a few more

  • WA.ui

    Show popups and messages, add buttons to the action bar, open windows and banners, add your own menu entries.

  • WA.room

    Know when someone enters or leaves an area or a layer. Show and hide layers, change tiles, place websites on the map.

    Area zones →
  • WA.player

    Read the name and tags of the player, follow where they walk, move them, and keep values that belong to them.

  • WA.state

    Room variables. Change one and it changes for everyone in the room, right away.

  • WA.event

    Send short messages between the scripts of different players, to everyone or to one person.

  • And more

    Chat, sound, the camera, navigation between rooms, player controls and the other players around you.

A small example

A door that opens for everyone

One player presses space, and the door layer disappears on every screen in the room.

script.ts
// Wait until the map is ready
WA.onInit().then(() => {
  // When someone walks into the area called "door"...
  WA.room.area.onEnter('door').subscribe(() => {
    // ...offer to open it
    WA.ui.displayActionMessage({
      message: 'Press space to open the door',
      // doorOpen is a room variable, so everyone sees it change
      callback: () => WA.state.saveVariable('doorOpen', true),
    })
  })

  // Runs for every player in the room when the value changes
  WA.state.onVariableChange('doorOpen').subscribe((open) => {
    if (open) WA.room.hideLayer('closed-door')
  })
})
Two ways to share

Scripts run in each browser

  • Variables

    Values that are stored. A room variable is shared by everyone in the room. A player variable belongs to one person. They can be kept between visits.

  • Events

    Messages that are not stored. Good for things that happen now and are gone a moment later.

  • Who may read and write

    For each room variable you choose who can read it and who can change it.

For builders

How scripts get on a map

A script is plain JavaScript, or TypeScript that you build to JavaScript. You name it in a property of the map, and it loads for every player who enters.

Scripts run in the browser of each player, inside an iframe. To change something for everyone, use a variable or an event.

Room variables are declared on the map itself, as objects in an object layer.

Language
JavaScript or TypeScript
Runs in
The browser of each player
Shared state
Variables and events
From
WorkAdventure

Ready to script your world?

Start with the docs and a small script on your own map.