- Joined
- May 3, 2016
- Messages
- 3,114
- Solutions
- 7
- Reaction score
- 2,480
- Points
- 145
- Favorite Pinball Machine
- Attack From Mars
I've been modifying some of Roney Pinball's tables, and I wanted to share something clever I discovered in his scripting. If you've ever looked at his code, you'll notice he has an ingenious method for handling background music.
To start using his approach, add the following line of code inside Sub FuturePinball_BeginPlay():
When you want to play a specific background music track, simply call PlayMusicForMode(1), PlayMusicForMode(2), or PlayMusicForMode(3). There's no need to manually stop the current track — it's handled automatically. Just insert the PlayMusicForMode() call wherever you'd like the music to begin. If you have more than three music tracks, you can easily add more cases to the script. To stop the music entirely, call PlayMusicForMode(0). It also simplifies sound level adjustments, since all the background music is centralized in a single subroutine.
This method might be useful on tables where you're running short on available music channels. It only uses two channels for all background music. However, keep in mind that this method isn't suitable for effects like ball rolling sounds, since those need to play simultaneously with background music. Even so, this approach can help you free up music channels for other uses.
Here’s the main code, which is fairly straightforward:
To start using his approach, add the following line of code inside Sub FuturePinball_BeginPlay():
Code:
MusicChannelInUse = 0
When you want to play a specific background music track, simply call PlayMusicForMode(1), PlayMusicForMode(2), or PlayMusicForMode(3). There's no need to manually stop the current track — it's handled automatically. Just insert the PlayMusicForMode() call wherever you'd like the music to begin. If you have more than three music tracks, you can easily add more cases to the script. To stop the music entirely, call PlayMusicForMode(0). It also simplifies sound level adjustments, since all the background music is centralized in a single subroutine.
This method might be useful on tables where you're running short on available music channels. It only uses two channels for all background music. However, keep in mind that this method isn't suitable for effects like ball rolling sounds, since those need to play simultaneously with background music. Even so, this approach can help you free up music channels for other uses.
Here’s the main code, which is fairly straightforward:
Code:
Sub PlayMusicForMode(Mode)
If (CurrentMusicTunePlaying <> Mode) Then
Dim ThisChannel, NextChannel
If (MusicChannelInUse = 1) Then
ThisChannel = 1
NextChannel = 2
MusicChannelInUse = 2
Else
MusicChannelInUse = 1
ThisChannel = 1
NextChannel = 2
End If
Select Case (Mode)
Case 0: EffectMusic ThisChannel, FadeOutAndStop, 0.0, 1000
EffectMusic NextChannel, FadeOutAndStop, 0.0, 1000
Case 1: PlayMusic NextChannel, "InGame_Theme", True, 1
EffectMusic NextChannel, PlayAndFadeIn, 1.0, 1000
EffectMusic ThisChannel, FadeOutAndStop, 0.0, 1000
Case 2: PlayMusic NextChannel, "Attract_Mode_Theme", False, 1
EffectMusic NextChannel, PlayAndFadeIn, 1.0, 1000
EffectMusic ThisChannel, FadeOutAndStop, 0.0, 1000
Case 3: PlayMusic NextChannel, "Multiball_Theme", false, 1
EffectMusic NextChannel, PlayAndFadeIn, 1.0, 1000
EffectMusic ThisChannel, FadeOutAndStop, 0.0, 1000
End Select
CurrentMusicTunePlaying = Mode
End If
End Sub
Last edited: