TypeScript definitions of the API are available as the @mapeditor/tiled-api NPM package, which can provide auto-completion in your editor. The API reference is generated based on these definitions.
A few example scripts and links to existing Tiled extensions are provided at the Tiled Extensions repository: https://github.com/mapeditor/tiled-extensions
The full scripting API and support for ECMAScript 7 features are only available for Tiled builds based on Qt 5.12 or later. This currently excludes the Windows XP and snap releases before Tiled 1.8.1.
Extensions can be placed in a system-specific or project-specific location.
The system-specific folder can be opened from the Plugins tab in the Preferences dialog. The usual location on each supported platform is as follows:
The project-specific folder defaults to “extensions”, relative to the
directory of the
.tiled-project file, but this can be changed in the
Since Tiled 1.7, project-specific extensions are only enabled by default for projects you created. When opening any other project, a popup will notify you when the project has a scripted extensions directory, allowing you to enable extensions for that project.
Always be careful when enabling extensions on projects you haven’t created, since extensions have access to your files and can execute processes.
An extension can be placed either directly in an extensions directory, or in a sub-directory. All scripts files found in these directories are executed on startup.
When using the
modules. They will then be able to use the import and export statements
also don’t pollute the global scope, avoiding potential name collisions between
When any loaded script is changed or when any files are added/removed from the extensions directory, the script engine is automatically reinstantiated and the scripts are reloaded. This way there is no need to restart Tiled when installing extensions. It also makes it quick to iterate on a script until it works as intended.
Apart from scripts, extensions can include images that can be used as the icon for scripted actions or tools.
In the Console view (View > Views and Toolbars > Console) you will find a text entry where you can write or paste scripts to evaluate them.
You can use the Up/Down keys to navigate through previously entered script expressions.
To execute a script (
.js) or to load a module (
.mjs) from the
command-line, you can pass the
--evaluate option (or
-e), followed by
the file name. Tiled will quit after executing the script.
The UI will not be instantiated while evaluating scripts on the command-line.
This means functions that rely on the UI being present will do nothing and some
properties will be
null. However, scripts are able to load and save maps
and tilesets through the available formats (see
tiled.tilesetFormats), as well as to make any modifications to these
Any additional non-option arguments passed after the script file name are
available to the script as
If you want to evaluate several scripts, use
--evaluate for each file. Note
.mjs) does not work, since
modules are loaded only once.
See the Tiled Scripting API.
The following global variable is currently not documented in the generated documentation, since it conflicts with nodejs types:
The file path of the current file being evaluated. Only available during initial evaluation of the file and not when later functions in that file get called. If you need it there, copy the value to local scope.