Export map grid as C array

Hello,

I am creating a 2D RPG game as a project in my computer engineering course entirely in C.
I have not been trying out Python at all but I do know that you are able to write Python scripts for custom exports using Tiled.

Is it possible to write a script that exports the map as an array as such:
{1,2,3,4,5,6},
{1,2,3,4,5,6},
{1,2,3,4,5,6}

If yes, then how do I do that properly in Python?

Cheers

If you can get the Python plugin to work (which I think is doable on Windows, but won’t currently work on macOS and I’m also not sure how to do it on Linux), then you can indeed solve this with a Python script. If you can write Python, then I’m sure you can adjust the example in the documentation to write out your map in your desired format.

It may be easier to write this in JavaScript instead. For that, you need to install the “snapshot” version of Tiled and write a startup.js script that registers your custom map format. You can read about how to do this in the latest documentation.

Hi I know I am 3 years late. But do you have any updates on this. In a similar situation where i want to export a tilemap as an array (every index representing the place in the spritesheet)

As with any custom export format, the way to go is still to write a custom script that implements a custom MapFormat. The link above is broken since the documentation was moved, the current registerMapFormat docs are here.

You can also look into the built-in CSV export format, which exports each layer as a CSV file with the tile data. You may need to enable this format in Edit > Preferences > Plugins.

2 Likes