class Stopwatch : ActionRole() { var seconds = 0 var todaysHigh = 0 var allTimeHigh = 0 override fun activated() { update() todaysHigh = Rain.getTodaysHighScore() allTimeHigh = Rain.getAllTimeHighScore() } override fun createAction() = ( Delay(1.0) thenOnce this:>nextSecond ).forever() fun stop() { replaceAction( null ) } fun nextSecond() { seconds++ update() } fun update() { actor.textAppearance.text = DollsHouseProducer.timeString(seconds) if ( seconds > 0 ) { if ( seconds == allTimeHigh ) { actor.event( "allTimeHigh" ) } else if ( seconds == todaysHigh ) { actor.event( "todaysHigh" ) } } } }