interface Switchable : Role { fun switch(value: bool) } class Switch : AbstractRole(), ContactListenerRole { @Attribute var on: bool = true @Attribute var controls: String = "" override fun activated() { super.activated() update( on ) } override fun tick() { } override fun beginContact(contact: Contact, otherActor: Actor) { val otherRole = otherActor.role if (otherRole is DollPart) { update( !on ) } } fun update( state : bool ) { on = state actor.event(if (on) "on" else "off") for( switchable in actor.stage.findRolesByClass(Switchable) ) { if (switchable.actor.name == controls) { switchable.switch(on) } } } override fun endContact(contact: Contact, otherActor: Actor) {} }