This directory contains all map-related scripts that will be executed in the browser by WorkAdventure.
main.ts: Main map script (referenced in.tmjfiles)
All map scripts MUST be placed in this src/ directory to work correctly. Scripts placed elsewhere will NOT be compiled and will cause errors.
Scripts in this directory are:
- β Automatically transformed from TypeScript to JavaScript
- β
Bundled with npm dependencies (like
@workadventure/scripting-api-extra) - β
Served with correct MIME types (
application/javascript) - β
Referenced in
.tmjfiles using paths likesrc/main.ts
- Create your TypeScript script in
src/(e.g.,src/my-script.ts) - Reference it in your
.tmjfile'sscriptproperty:"src/my-script.ts" - The script will be automatically compiled and bundled when accessed
// src/main.ts
import { bootstrapExtra } from "@workadventure/scripting-api-extra";
WA.onInit().then(() => {
console.info('Map script loaded!');
// Your map logic here
});Then in your .tmj file:
{
"properties": [
{
"name": "script",
"type": "string",
"value": "src/main.ts"
}
]
}- β Don't place map scripts in
app/(reserved for the server entry point) - β Don't place map scripts in
public/(static files) - β Don't place map scripts in the root directory
- β Don't reference scripts outside
src/in your.tmjfiles
See the main README.md for more information about the project structure.