New to Defold, programming in Lua a decade or so.
The actual problem I am trying to solve right now is hide/show of objects, and am using scale to 0 to hide the objects. Works fine. But the problem is restoring the object if the original scale was not 1.0. I do a similar thing ‘restoring’ objects moved to their starting place in a lot of games, restoring to default of many attributes is a technique I use a lot.
My typical solution in other Lua-based game engines is to create custom properties to store the original scale or position or color or whatever. In Lua, it is easy, just object.property = whatever. But Defold has disabled setting arbitrary properties, and I get the ‘large team’, ‘corporate long-term support’, structured programming reasons for this (but I am now a retired solitary programmer). I am struggling to find a workaround.
Using go.property seems reasonable, except that it puts the property on a script, not on the object, so other scripts (eg common modules) have to jump through hoops to find them and it also requires having a script attached to every object, which seems silly. Similar with using messages to store information. But I guess putting a script on every object and sending it a message or creating script properties are perhaps the only choices I have?
For now, I am creating a storage module (shared) in which I have a table where I put original scale for every object before changing the scale. This is not a bad solution, I think.
What is the right Defold way to save/restore information like this? Is there a way to change or subclass the game object to put these extra properties on all of my game objects by default?
Thanks for any help.