New End Action: Sound And Advance (4.1)

Bucket Mouse

Active member
To add sound effects to my cutscenes, I had to modify the Advance script in TimerEndScripts to create a variant that would command to play a sound effect, then advance the sprite action to a step that requires that sound effect.

I thought other people might find it useful too, so here it is. It can be used for several different sounds if you assign them to a specific screen (as I have done below), or if you just want to use one sound, you could comment out everything above ;;is advance action except the PlaySound command.

Save it as SoundAndAdvance.asm, then assign it to one of the unused End Scripts in Script Settings.

Code:
    LDA currentScreen
	CMP #$20 ;; this is screen 0,2
	BNE +
	
		PlaySound #$01 ; beep
		
	+
	CMP #$09 ;; this is screen 9,0
	BNE ++
	
		PlaySound #$04 ; explosion
		
	++

;; is advance action
	LDA Object_action_step,x
	AND #%00000111
	CLC
	ADC #$01
	CMP #$08
	BCC isAGoodActionStepValue2
	;; is over 8, so go back to 1

	ChangeObjectState #$00,#$02
	JSR DoNewAction
	JMP actionTimerFinished
isAGoodActionStepValue2:
	STA temp
	ChangeObjectState temp,#$02
	JSR DoNewAction
 

Bucket Mouse

Active member
NNNNNGH, never mind about the End Action part. It turns out you can only have two sounds at the most with this thing before you get a Branch Out Of Range error. That's because End Actions are connected to this little bit of script in HandleUpdateObjects:

Code:
dontWarp:
	CMP #$0A
	BNE dontUser1
	.include SCR_TIMER_END_10
	JMP actionTimerFinished

You're better off using this as a plain AI Action, and only using the End Action thing if you run low on AI space. To do that you just rip the sounds part and save it in your AiScripts folder:

Code:
    LDA currentScreen
	CMP #$20 ;; this is screen 0,2
	BNE +
	
		PlaySound #$01 ; beep
		
	+
	CMP #$09 ;; this is screen 9,0
	BNE ++
	
		PlaySound #$04 ; explosion
		
	++

Am I confusing everybody? Probably. Oh well.
 

dale_coop

Moderator
Staff member
When you have Branch out of Range error on those lines:
Code:
	CMP #$0A
	BNE dontUser1
	.include SCR_TIMER_END_10
	JMP actionTimerFinished
You can change them into:
Code:
	CMP #$0A
	BEQ + 
		JMP dontUser1
	+
	.include SCR_TIMER_END_10
	JMP actionTimerFinished
This will fix the error.
 
Top Bottom