Getting Object specific data and potential solution?

data in traits class is the base Object all object classes derive from that can hold traits.

This is the way I worked on some data for Lamps.

package arm;

class LightFlicker extends iron.Trait {

	var lamp:iron.object.LampObject;

	public function new() {
		super();

		 notifyOnInit(function() {
			 lamp = cast object; 
		 });

		 notifyOnUpdate(function() {
			  lamp.data.raw.strength = Math.random() * 10;
		 });
	}
}

But it seems a bit redundant?
See object already refers to the LampObject If it’s attached to such an object. But due to its interface it’s always referring to the base class and all data for LampObjects are hidden. To fix this I had to add a new field that basically refers to the same thing but more specifically by casting it.

Would there be a solution to specify what object is?

Perhaps something like

 package arm;

@:stricttrait(iron.object.LampObject)
class LightFlicker extends iron.Trait {

	public function new() {
		super();

		 notifyOnUpdate(function() {
			  object.data.raw.strength = Math.random() * 10;
		 });
	}
}

Perhaps such a system can also lend itself to Blenders interface separating the script lists based on the object types you can only apply it to?

Don’t forget to check out the Armory API around Scene and Trait as you’ll find most of your answers there. If I had to guess this is what you want.

// name of “Lamp” can be any lamp you renamed in blender
lamp = iron.Scene.active.getLamp(“Lamp”);

That’s not so much a solution to the issue tho. Some traits will work directly on the object. Your solution doesn’t only require me to fetch the same object im already on it needs a static string input…to fetch itself… Imagine having several lights and having to fetch them all. That’s a big no no. The simplicity of traits is that they have information on their enitity.

I have no issue with casting the object field to the required type but seems a bit redundant. My example will only work on lampobjects and therefor would never put them on something else.