Timing change for death handler script (Dying.sc)

From SCI Wiki
Jump to: navigation, search

Originally posted on the SCI Programming Forums by Gumby.

I just utilized the dying.sc script for the first time and I immediately noticed that there is a significant delay between calling the the script and the death 'screen' popping up.

This is by design, but I didn't like the fact that the delay length was hard-coded into script. Making a few modifications, I exposed the delay property for the script:

(instance public DyingScript of Script
	    seconds 3	     //  Exposed this property (just by adding it here), 
        )                    //  which is inherited from the Script class & set the default to 3
	(method (changeState newState)
		(var mbResult, message)
		= state newState
		(if(== state 0)
			(send gTheMusic:fade())
			(send gRoom:setScript(0))
			Load(rsSOUND 2)
			//= seconds 3     // Commented out this line, which set the delay to 3 seconds
  			(if(== state 1)


So now, when I call the dying script, I can specify seconds like so:

  (send dyingScript:
       seconds(1)   //  You can set this to however long you wish, based on your animation length
       register("You are dead.")

  If you need more granularity than seconds, it would be simple to expose the 'cycles' property instead of the 'seconds' property in the Script class, then change the dying script to use cycles instead of seconds.