{.section-title.accent.text-primary} # Scripting WorkAdventure maps Do you want to add a bit of intelligence to your map? Scripts allow you to create maps with special features. You can for instance: * Create FTUE (First Time User Experience) scenarios where a first-time user will be displayed a notification popup. * Create NPC (non playing characters) and interact with those characters using the chat. * Organize interactions between an iframe and your map (for instance, walking on a special zone might add a product in the cart of an eCommerce website...) * etc... Please note that scripting in WorkAdventure is at an early stage of development and that more features might be added in the future. You can actually voice your opinion about useful features by adding [an issue on Github](https://github.com/thecodingmachine/workadventure/issues). {.alert.alert-warning} **Beware:** Scripts are executed in the browser of the current user only. Generally speaking, scripts cannot be used to trigger a change that will be displayed on other users screen. ## Scripting language Client-side scripting is done in **Javascript** (or any language that transpiles to Javascript like _Typescript_). There are 2 ways you can use the scripting language: * **In the map**: By directly referring a Javascript file inside your map, in the `script` property of your map. * **In an iFrame**: By placing your Javascript script into an iFrame, your script can communicate with the WorkAdventure game ## Adding a script in the map Create a `script` property in your map. In Tiled, in order to access your map properties, you can click on _"Map > Map properties"_.
The Map properties menu
Create a `script` property (a "string"), and put the URL of your script. You can put relative URLs. If your script file is next to your map, you can simply write the name of the script file here.
The script property
Start by testing this with a simple message sent to the chat. **script.js** ```javascript WA.chat.sendChatMessage('Hello world', 'Mr Robot'); ``` The `WA` objects contains a number of useful methods enabling you to interact with the WorkAdventure game. For instance, `WA.chat.sendChatMessage` opens the chat and adds a message in it. The message should be displayed in the chat history as soon as you enter the room. {.alert.alert-warning} Internally, scripts are running inside a [sandboxed iframe](https://blog.dareboost.com/en/2015/07/securing-iframe-sandbox-attribute/). Furthermore, the script itself is loaded as module with ` ``` You can now start by testing this with a simple message sent to the chat. **iframe.html** ```html ... ... ``` Let's now review the complete list of methods available in this `WA` object. ## Using Typescript View the dedicated page about [using Typescript with the scripting API](using-typescript). ## Available features in the client API The list of available functions and features is [available in the API Reference page, with examples](api-reference).