I'm fairly new to this as well, and JPSalas' tables have been a great help in learning. I'm using his Pokémon table as a reference to create my own. Below is something that’s working for me—it's not complete, but hopefully, it's a good starting point. There are probably some missing elements, but so far, it’s been effective for me. Although the Table crashes once you reach the BallsPerGame total of 6 balls.
'--- Constants ---
Const BallSize = 50 ' Ball radius size
Const MaxMultiballs = 5 ' Maximum number of balls allowed on the playfield at once
Const BallsPerGame = 6 ' Total number of balls available for the game
'--- Variables ---
Dim BallsRemaining ' Tracks how many balls are left in the game
Dim BallsOnPlayfield ' Tracks the number of balls currently in play
BallsOnPlayfield = 0
BallsRemaining = BallsPerGame
'--- Multiball Variables ---
Dim mBalls2Eject ' Number of balls left to be ejected for multiball
Dim bMultiBallMode ' Flag to indicate if multiball mode is active
'--- Initialization ---
Sub Table1_Init()
mBalls2Eject = 0
bMultiBallMode = False
CreateMultiballTimer.Enabled = False ' Ensure the timer starts in a disabled state
End Sub
'--- Start Multiball ---
Sub StartMultiball(balls)
AddMultiball(balls) ' Add the specified number of balls to multiball queue
End Sub
'--- Ball Creation Logic ---
' This function adds balls to the queue and starts the timer to release them one at a time
Sub AddMultiball(nballs)
mBalls2Eject = mBalls2Eject + nballs ' Add new balls to the queue
CreateMultiballTimer.Enabled = True ' Start the timer to release them one by one
End Sub
' Timer event that controls ball release one at a time
Sub CreateMultiballTimer_Timer()
If mBalls2Eject > 0 And BallsOnPlayfield < MaxMultiballs Then
CreateNewBall() ' Create a new ball and kick it into play
mBalls2Eject = mBalls2Eject - 1 ' Decrease the count of balls left to eject
' Stop the timer only when all balls have been ejected
If mBalls2Eject = 0 Then
CreateMultiballTimer.Enabled = False
End If
Else
' Safety check to prevent infinite loops
CreateMultiballTimer.Enabled = False
End If
End Sub
' Function to create and launch a new ball into play
Sub CreateNewBall()
If BallsRemaining > 0 Then ' Only create a new ball if there are any left in the game
BallRelease.CreateSizedBall BallSize / 2 ' Spawn a new ball
BallRelease.Kick 90, 7 ' Kick the ball into play (90 degrees, strength 7)
BallsOnPlayfield = BallsOnPlayfield + 1 ' Increase the count of active balls
BallsRemaining = BallsRemaining - 1 ' Decrease the count of balls left in the game
If BallsOnPlayfield > 1 Then bMultiBallMode = True ' Enable multiball mode
End If
End Sub
'--- Drain Handling ---
' When a ball drains, decrease the count of active balls
Sub Drain_Hit()
Drain.DestroyBall ' Remove the ball from play
BallsOnPlayfield = BallsOnPlayfield - 1 ' Update the number of balls in play
' If all balls drain and multiball was active, reset multiball mode
If BallsOnPlayfield = 0 And bMultiBallMode Then
bMultiBallMode = False
' Additional logic for ending multiball mode can go here
End If
End Sub
'--- Multiball Trigger Event ---
' This function is triggered when a ball lands in Kicker001
Sub Kicker001_Hit()
AddMultiball 3 ' Start a multiball sequence by adding 3 balls
CreateMultiballTimer.Interval = 1000 ' Set the delay for each ball release
End Sub