Export Object Types not including defaults

Hi, when I json export an Object that has properties defined from “Object Types” panel, the defaults are not exported therefore I need to do several checks in the js to avoid undefined parameters. Is this “by design” or am I missing something? I guess it could behave like this to save memory when loading the json level data?

Right, it behaves like that to save memory and reduce file size based on the assumption that most of the time you will not change all your default values.

You’re not the first to ask though and I could consider to add an option to include these values in exports. However, for regular saving they would still need to be left out since the presence of a value currently also means “default value has been overridden”. That is in order for unchanged properties to change along when the default value is changed.

I think that a workaround would be to display a “Blueprint” object in the JSON and in the instances have a reference id for example:

{
  "objects":[
  {
    "gid":2,
    "type":"enemy",
    "objectTypeID" : 10
  }],
  "objects-type": {
    "10" : {
      "speed": 10,
      "velocity": 0.5,
      "canFly": true
    }
  }
}

Then in a language like javascript I can easly get the “objects-type” once and merge the defaults with Object.assign and avoid to check for undefined variables.

Right, except there is no “object type ID” since the types are simply referred by name. The only thing missing is to include the object type definition in the map file, but in general that’s superfluous since they are already stored in the objecttypes.xml file.

So, things could be made easier for people using JSON in two ways:

  • Support JSON as format for objecttypes.xml, so that it will be easier to read if you’re already using JSON.
  • Embedding used types in the export, so that no additional file needs to be read (though in general, I’d expect most games will load their object types file somewhere else and would not need this).

Thanks for the reply,
I think your first solution would be perfect because you avoid all duplication that would arise when exporting the object directly in the map, which I had suggested in my previous post.

BTW, Tiled is awesome and very easy to use, I learned it very quickly :slight_smile:

1 Like

Alright, I’ve just implemented it:

That’s great to hear! Even so, I’m still working on a Tiled Manual to make sure all the hidden features are written down somewhere.

Alright, I’ve just implemented it:

This is awesome! Do I need to wait for the release of the next version before I can use it?

That’s great to hear! Even so, I’m still working on a Tiled Manual2 to make sure all the hidden features are written down somewhere.

Yes I have been reading it. This is kind of Off topic, but I don’t understand the Typed Tiles functionality. Does it mean that I can set the tile type before I place the tile as an object in the map?

I’ve just pushed it to the snapshot branch, so if you have a development snapshot build installed it should update soon (and if you haven’t already, install a development snapshot to get this feature before the Tiled 1.0 release).

This feature can save you time by displaying default properties of selected tile objects in the Properties view, based on the type set on their tile (before Tiled 1.0, you’d have to specify the type on each tile object to see the default properties for that type).

If that explained it, please let me know how you think the documentation could be improved. :slight_smile:

I don’t know what a snapshot is. I am using Windows 8, do I need a compiler?

I have Tiled 0.18.2, is that a previous version with less features then?

Ah, the development snapshots are compiled versions of Tiled linked on the download page on itch.io, under “Download and install instructions from Thorbjørn”. They are made available in between versions, so they are more recent than Tiled 0.18.2 but not Tiled 1.0 yet. Usually they are updated about weekly and they are available for Windows, macOS and Linux.

1 Like