I am using Tiled’s export feature vie CLI. For the most part it has been working. But as my maps become larger and I add more layers with even more objects, some of the information that should be exported is not being exported. For instance, here is a code snippet:
objectLayer is a layer passed as an argument to a function.
Just about ever object is assigned a tile from a tileset. But some objects will have tileset info and some won’t. But the object’s tile is from the same tileset.
Anyone have a clue what could be causing this? I use loops to process each layer and a loop for object processing.
What is the actual error you’re getting? Is it random (i.e. different objects throw the error every time), or consistent (the same objects always cause the error)? Also, in recent versions of Tiled, you have to use tiled.log, console.log does not work.
You’re using tileset.name to construct a path, but tileset.name is the string name of the tileset, which might not be set and might not be related to the file name. Did you mean to use tileset.fileName?
So tile.tileset is null sometimes. This can happen if the tile becomes removed from its tileset after being used somewhere, which is very uncommon and isn’t very likely to be something you do in an export script.
Is it always the same objects affected, or is it random? If it’s random, it might be issue #3565, where values that should not be null are null sometimes, at random. I haven’t seen it affect Tile.tileset before, but maybe it’s possible.
What version of Tiled are you using, and what is the Qt version (type tiled.qtVersion into the Tiled console to check)? This particular issue affects some Qt versions more than others. The fact that console.log apparently works for you suggests you’re using a rather old version of Tiled, which would be affected by this bug.
Crud! I rewrote the code to be inline and it still fails, even with accessing the arrays directly. I cannot figure out a work around and my map format is blown to bits now. This puts my game on hold.
While the related PR is still WIP since there appears to be some leaking issue causing tilesets to not get deleted on shutdown, it should already work around the issues with the garbage collector, because now the script API wrapper objects are owned by C++ rather than the JS engine.
You have to be logged in on GitHub, and you should be able to scroll down on the first page bjorn linked and download the build appropriate for your OS.