Code/Example Help BAM FizX FizX Lite FP Ball rolling sound not playing

Coding and examples for future Pinball and BAM
Future Pinball

FireDragon76

Pinball Wizard
Joined
Apr 5, 2023
Messages
137
Reaction score
19
Points
18
Favorite Pinball Machine
Spirit of 76
I am working on trying to implement FizX Lite on Eight Ball Deluxe. I got it working on Popotte's Bally Star Trek (1978) just fine. I also included ball rolling sounds from the FizX All-in-One table. But for some reason, the code doesn't work on Eight Ball Deluxe. Debug window says ball rolling sound is playing (and gives consecutive numbers 1....2...3, each time the timer ticks over and the ball rolls), but it doesn't say the name of the sound, as it does in the Star Trek table, and no sound can be heard playing:

Code:
'
' ################## BALL ROLLING SOUNDS - FP ##################

' By Nailbuster, TerryRed, Popotte
' Version: 2.1
' Dec - 2022, Mar 2023

' - add this code to your table starting at "BALL ROLLING SOUNDS - FP" and ending at "END OF BALL ROLLING SOUNDS - FP".
' - add a timer named BallRolling_Update_Timer ("Timer Enabled" unchecked and "Time Interval" set to 150)
' - add a timer named Timer1 ("Timer Enabled" checked and "Time Interval" set to 75)
' - add desired BallRolling_Sound files to Music Manager
' - change Ball Rolling Sound Settings as needed
' - run Ball_Rolling_Sounds_Start on table startup
' - Add the following line of code (without apostrophe) as a separate line to "Sub ResetForNewPlayerBall()".
' FlagRamp = 0

DIM BallRolling_Sound_Enabled
DIM FP_BallRoll_Max_Volume
DIM FP_BallRoll_Active_Volume
DIM FP_BallRolling_Channel
DIM BallRolling_Sound
DIM BallRolling_Sound1
DIM BallRolling_Sound2
Dim FlagRamp
Dim TrackedBalls(6)     

' ################## Ball Rolling Sound Settings ##################

Sub Ball_Rolling_Sound_Settings
    BallRolling_Sound_Enabled = true                    ' enable Ball Rolling Sounds (true or false)
    FP_BallRoll_Max_Volume = 0.6                        ' Future Pinball ball rolling max volume (default = 1)
    FP_BallRolling_Channel = 8                            ' PlayMusic channel that is NOT used by anything else on the table!!!
    BallRolling_Sound1 = "mech_ballroll_wood"    ' ball rolling sound for playfield - add sound file to Music Manager
    BallRolling_Sound2 = "mech_ballroll_metal"    ' ball rolling sound for ramp - add sound file to Music Manager
End Sub

                               ' max number of balls that will have ball rolling sounds (no more than 6)

' ############### Ball Rolling Sound Settings - END ###############


' *** Ball Rolling Sound Tuning (FP) ***

Dim i

Const BallVelTuning = 25
Const BallVolTuning = 2300

Function BallSpeedVol(ball) ' Calculates the Volume of the sound based on the ball speed
    BallSpeedVol = (zfunBallVel(ball) ^2) / BallVolTuning
    if (BallSpeedVol>1.0) then    BallSpeedVol=1.0
End Function

Function BallSpeedPitch(ball)    ' Calculates the pitch of the sound based on the ball speed
   BallSpeedPitch = round(100+zfunBallVel(ball)/4)
    if (BallSpeedPitch>120) then BallSpeedPitch=120 end if
End Function

Function zfunBallVel(ball)    ' Calculates the ball speed
    zfunBallVel = INT(  SQR(  (ball.velocity.x^2 + ball.velocity.y^2)   )/BallVelTuning )
End Function

Function BallPan(ball)    ' not used - Calculates the panning (left/right) for a ball based on the X position on the table.
   Dim tmp
   tmp = ball.PositionGlobal.x * 2 / ((xBAM.Table.width)-1)
   If tmp > 0 Then
      BallPan = (tmp ^10)
   Else
      BallPan = (-((- tmp) ^10))
   End If
End Function

' *** Ball Rolling Sound Tuning (FP) - END ***

DIM bAudioW:bAudioW=xBAM.Table.width        'table width
DIM bAudioH:bAudioH=xBAM.Table.length        'table length

ReDim GlobalBallsArray(-1)

Sub GetBallsCallback(ball)
    ReDim Preserve GlobalBallsArray(UBound(GlobalBallsArray) + 1)
    Set GlobalBallsArray(UBound(GlobalBallsArray)) = ball
End Sub

Function GetBalls(max)
    ReDim Preserve GlobalBallsArray(-1)
    xBAM.EnumBalls max, 0, "GetBallsCallback"
    GetBalls = GlobalBallsArray
End Function

Function FindEmptyVoice
    FindEmptyVoice = -1
    For i=0 to Ubound(TrackedBalls) -1
        If IsEmpty(TrackedBalls(i)) Then
            FindEmptyVoice = i
            Exit For
        End If
    Next
adddebugtext "EmptyVoice= " &i
End Function

Const MinSpeed = 1


Dim Toto

Sub UpdateBallSound(ByRef tmpball, bIndex)
    dim xpos,ypos     
    xpos= ((tmpball.PositionGlobal.x / bAudioW) * 20) - 10
    ypos= ((tmpball.PositionGlobal.y / bAudioH) * -10)
    if tmpball.speed>1 Then
        If tmpball.ExtFloat3 <> 1 Then Exit Sub
        FP_BallRoll_Active_Volume = (BallSpeedVol(tmpball))*(FP_BallRoll_Max_Volume*10)    ' FP ball volume level
        EffectMusic FP_BallRolling_Channel, SetVolume, FP_BallRoll_Active_Volume, 0
        EffectMusic FP_BallRolling_Channel, SetFrequency, 0, BallSpeedPitch(tmpball)        ' FP ball pitch
Toto = Toto +1: adddebugtext "Ball sound= "&BallRolling_Sound &" " &Toto
        'AddDebugText "BallRoll Vol = " & FP_BallRoll_Active_Volume
        'AddDebugText "BallRoll Freq = " & BallSpeedPitch(tmpball)
        'AddDebugText "BallSpeed = " &tmpball.speed
    Else
        EffectMusic FP_BallRolling_Channel, SetVolume, 0, 0
    end if
End Sub

Sub CheckBallSound()
    For i=0 to Ubound(TrackedBalls) -1
        If Not IsEmpty(TrackedBalls(i)) Then
            If TrackedBalls(i).Exist Then
                UpdateBallSound TrackedBalls(i),i
            Else
                EffectMusic FP_BallRolling_Channel, SetVolume, 0, 0    ' turn off vol on destroyed balls (fp)
                AddDebugText "Stop FP Ball Rolling: Vol = 0"
                TrackedBalls(i).ExtFloat3 = 0    ' If we stop sound, because ball is too slow, we mark this ball as not tracked, 0 is default value
                TrackedBalls(i) = Empty            ' ... and we forgot about this ball
            End If
        End If
    Next
End Sub

Sub BallRolling_Update_Timer_Expired()
    CheckBallSound()
    Dim BOT, b, i
    BOT = GetBalls(Ubound(TrackedBalls))    ' we don't need more balls, than we can track
    For b = 0 To UBound(BOT)
        If Bot(b).ExtFloat3 = 0 Then                ' we want to add only balls not tracked already
adddebugtext "Not yet tracked"
            If Bot(b).Speed <= MinSpeed Then Exit For    'all other balls are too slow... no need to check
            i = FindEmptyVoice()
            If i = -1 Then Exit For                ' we don't have empty voice slots
            Set TrackedBalls(i) = Bot(b)
            TrackedBalls(i).ExtFloat3 = 1
            ' start playing FP Ball Rolling sound (looped, and volume at 0)
            PlayMusic FP_BallRolling_Channel, BallRolling_Sound, true ,0 ,0
            AddDebugText "Start FP Ball Rolling on PlayMusic Channel: " & FP_BallRolling_Channel
            UpdateBallSound TrackedBalls(i),i
        End If 
        If Bot(b).ExtFloat3 = 3 Then                ' balls already tracked but we change ball sound
adddebugtext "Not yet tracked"
            If Bot(b).Speed <= MinSpeed Then Exit For    'all other balls are too slow... no need to check
            Set TrackedBalls(b) = Bot(b)
            TrackedBalls(i).ExtFloat3 = 1
            ' start playing FP Ball Rolling sound (looped, and volume at 0)
            PlayMusic FP_BallRolling_Channel, BallRolling_Sound, true ,0 ,0
            AddDebugText "Change FP Ball Rolling on PlayMusic Channel: " & FP_BallRolling_Channel
            UpdateBallSound TrackedBalls(i),i
        End If 
    Next
End Sub

Sub Ball_Rolling_Sounds_Stop    ' Force Ball Rolling Sounds to be off
    BallRolling_Update_Timer.enabled = false
    EffectMusic FP_BallRolling_Channel, SetVolume, 0, 0
    AddDebugText "Ball Rolling Stopped"
End Sub

Sub Ball_Rolling_Sounds_Mute    ' Force Ball Rolling Sounds to be muted
    EffectMusic FP_BallRolling_Channel, SetVolume, 0, 0
    AddDebugText "Mute FP Ball Rolling"
End Sub

Sub Ball_Rolling_Sounds_Start
    Ball_Rolling_Sound_Settings
    if BallRolling_Sound_Enabled = true then BallRolling_Update_Timer.set True, 100
    AddDebugText "Ball Rolling Sound enabled: " & BallRolling_Sound_Enabled
End Sub

Sub Timer1_Expired
Dim Ball
    Set Ball = XBAM.BallCloseTo(367, 280, 6)
    If Ball.Position.X > 456 And Ball.Position.Y < 180 Then Exit Sub
  
    Select Case FlagRamp
        Case 0: If Ball.Position.Z < 18 Then Exit Sub                                                        ' we are always on the playfield
                FlagRamp = 1
                BallRolling_Sound = BallRolling_Sound2                                                            ' then we change the ball rolling sound
adddebugtext "We access the ramp " &FlagRamp &" " &BallRolling_Sound
        Case 1: If Ball.Position.Z > 18 Then Exit Sub                                                        ' we are always on the ramp
                FlagRamp = 0
                BallRolling_Sound = BallRolling_Sound1                                                            ' so we have to restore the normal rolling sound
adddebugtext "We leave the ramp "&FlagRamp &" " &BallRolling_Sound
    End Select
    Ball.ExtFloat3 = 3: BallRolling_Update_Timer_Expired                                                    ' we change the ball to not yet tracked (ExtFloat3 = 0) and we update the sound
End Sub


Ball_Rolling_Sounds_Start        'start Ball Rolling Sounds

' ################## END OF BALL ROLLING SOUNDS - FP ##################
 
Search for "playmusic 8" in the table. If it exists, you'll have to find a channel that is not in use and set FP_BallRolling_Channel = n where n is the available channel.

If all the 8 channels are already in use you'll have to find a solution :)
 
I got the script to work halfway in Spirit of 76. I went in and changed all the bells from being on the music channels, to playing as sounds. But for some reason, the ball rolling doesn't start until you hit a one of the playfield objects.

Any idea how to output a log of the debug? It rolls by so fast I can't read it.
 
The best choice is to send your table in order to see what is wrong. Just my opinion...
 
The best choice is to send your table in order to see what is wrong. Just my opinion...

OK. Both these should be run with the 1K ball, ideally.
 

Attachments

  • SpiritOf76 FZX Lite.fpt
    9.4 MB · Views: 3
  • Eight Ball Deluxe FZX Lite.fpt
    19.4 MB · Views: 3
Not all tables use a number for the music channels being used. Some tables use a variable instead, so be sure that the music channel you are using for ball rolling is not getting interrupted by something else on the table.
 
Not all tables use a number for the music channels being used. Some tables use a variable instead, so be sure that the music channel you are using for ball rolling is not getting interrupted by something else on the table.

Besides "PlayMusic", what other clues should I look for, to know if a given line of code involves a music channel?
 
I managed to put a bit of script into the table to log the debug screen. This is what it says

Code:
BAM Version: 360
FizX v2.00
Ball Rolling Sound enabled: True
Ball Rolling Sound enabled: True
Not yet tracked
EmptyVoice= 0
Start FP Ball Rolling on PlayMusic Channel: 8
Ball sound=  1
Ball sound=  2
Ball sound=  3
Ball sound=  4
Ball sound=  5
Ball sound=  6
Ball sound=  7
Ball sound=  8
Ball sound=  9

What does " EmptyVoice = 0 " refer to?
 
Well, the code you used for rolling sound is for balls and multilevel (playfield, ramp, ...).
Please, find the corrected tables.
 

Attachments

  • SpiritOf76 FZX Lite_JPR.fpt
    9.4 MB · Views: 1
  • Eight Ball Deluxe FZX Lite_JPR.fpt
    19.4 MB · Views: 1
Well, the code you used for rolling sound is for balls and multilevel (playfield, ramp, ...).
Please, find the corrected tables.

Thanks. What kind of mistakes were made in the code?

I may try adding solenoid sounds to the flippers in Eight Ball Deluxe. The table is already so noisy, though, that it might not make much difference.
 
I am having a similar problem with this file. The right flipper going up isn't producing a buzz, and the ball rolling sound cuts in late randomly:

Does it have something to do with this code?

Code:
' A Music Channel has finished Playing.
'
' Channel is set to the channel number that has finished.
'
Sub FuturePinball_MusicFinished(ByVal Channel)
End Sub

I have had luck with other tables, but for some reason a few give me problems.

Edit: NVM... I got it to work. Though I had to re-copy alot of the code from the original table.

Thanks for the help. I will upload the tables soon, after I playtest them some more, and give credit where it is due.
 
Last edited:
thats waiting for music to stop before another one takes over the channel. the nicer tables use most if not all channels

save your work every time you do something, youll find you can f... up a code by forgetting a comma or putting one after a number.
and ake sure your script follows vb6 format sub end sub and everything inside that sub is tabbeb
 
also fizx lite isnt using pup sff so it shouldnt be that big of a deal. I never tried the table though.
ive spend a month on the one im trying to finish
 
General chit-chat
Help Users
You can interact with the ChatGPT Bot in any Chat Room and there is a dedicated room. The command is /ai followed by a space and then your ? or inquiry.
ie: /ai What is a EM Pinball Machine?
  • No one is chatting at the moment.
  • Chat Bot Mibs Chat Bot Mibs:
    DrazeScythe has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Torntabittz has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    brotherboard has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    GARRY040 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    BL2K has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Chilldog has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    rodneyfitz has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    ace19120 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Tomasaco has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Greek_Jedi has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Beermano has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    02browns has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    nitram1864 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    aeponce has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    JEAN LUC has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    lorenzom has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    maxangelo19 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Dragonslapper has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    royaljet has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Tyfox has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Goldtopboy has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    slick267 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    dabreeze has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Spike has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Tofa has left the room.
      Chat Bot Mibs Chat Bot Mibs: Tofa has left the room.
      Back
      Top