Accessing template defaults in scripting API

Hello,

I am currently running into a problem while combining the use of templates (just drag and drop them on the map) and my custom scripts.
So far, when processing an object that was created by using a template, I have not been able to access the values of properties where the property still has the default value specified by the template (aka values that are greyed out in the UI).
I also don’t find a reference to the template on the object (even the type property is not set).

Maybe I am just missing something :smile:

Would appreciate any help here.

Thanks,
Christian

Hey @Laskoran, welcome!

This should be possible by using Object.resolvedProperty and Object.resolvedProperties.

Unfortunately here you’re running into an unfinished part of the scripting API, covered by the following issue:

Please feel free to comment there about your use-case. Maybe I can have a look at implementing this for the next release.

Thanks so much for the welcome :slight_smile:

The resolvedProperties are working nicely for my custom properties on the template. Thank you.

The non-custom property ‘type’ is unfortunately not retrievable by this, but for that, I can work around by adding a mirrored custom property with the same value as it is stored in ‘type’.

As of 1.9, there is no longer a “type”, there’s “className” instead, maybe that’s the problem? (I don’t know if that’s present in template objects though, maybe it’s not.)

Well, MapObject.type is still there for compatibility reasons. But the problem here is that there is currently no scripting access to MapObject::effectiveClassName, which takes into account tile objects and templates.

Also, I think in Tiled 1.8, accessing MapObject.type actually returned a type set on the template if it wasn’t changed for the instance, so it’s not entirely backwards compatible.

1 Like