Trying to use scripting API


(ILIUS) #1

Working on Windows with 1.2.2 version of Tiled.
Added startup.js with example code given here: https://doc.mapeditor.org/en/latest/reference/scripting/#script-registermapformat

Paced script into C:\ProgramData\Tiled and C:\Program Files\Tiled and even C:\Users\<user>\.tiled

But nothing seems to happen. No new format in Export As dialog.

Also I only have Debug Console in Toolbars wich doesn’t have any input. So I suppose it’s not the console mentioned here https://doc.mapeditor.org/en/latest/reference/scripting/#console-view?

What am I doing wrong?


How to map graphic tileset to ascii symbols?
(Thorbjørn Lindeijer) #2

You’re trying to use a feature that is only present in the development snapshots, while having the latest stable version of Tiled installed.

To use the scripting feature, you need to install the latest “snapshot” version of Tiled (currently version 2019.02.10, available at https://thorbjorn.itch.io/tiled).


(ILIUS) #3

Oh! I didn’t notice it! Thank you! And thank you for your effort!


(ILIUS) #4

One more question about Scripting API. I need some tiles info (type or additional custom properties) to use while exporting. As I understand it correctly currently I only have one option: tileset should be opened and then i can find it in tiled.openAssets array?

Also when I was reading tile data from gigantic tileset in loop. There have been data loses. Had to make temporary dictionary to prevent getting tile info for those I already got. But still it means it is not completely safe. Are there some async operations? What can be done to make it safe?

Thank you.


(Thorbjørn Lindeijer) #5

Actually TileLayer.tileAt returns a Tile reference, from which you should be able to get the type and custom properties. However, there is currently no way to look up the properties of the tile’s tileset yet.

I find it hard to understand exactly what you’re doing and what problem you are encountering. Could you share the relevant part of your script?


(ILIUS) #6

Oh I didn’t notice TileLayer.tileAt! Great thanks!

You can see all the little export code here:


Now it has that temp dictionary which I use to cache symbols for tiles I already found. But if I use TileLayer.tileAt (or Tileset.tile) everytime in a loop. It only writes the part of the export. At least I can easily reproduce it on a big map. Its like half of the map exported.