Bonus Collection Routine

JonPurpleHaze

Site Nudger
Staff member
NOTE: All the code is included in one place at the bottom of this article

BonusCollect uses the HoldBonus variable, and comes in two flavors. The first one gives out only the amount of bonus, unmultiplied, and then restores the bonus value back, and the ball returns to play.
We use the BonusCollectKicker, which is after the ramp divertor on the left red wire ramp, and leads to the left inner flipper lane. The kicker is "turned off" in the table editor (use the options menu, and click on the kicker object) as it looks a little weird in the actual game. We first add a light, in this case called BonusCollectLight. We placed it at the start of the red ramp, as this is where the ball will travel. We start by seting the Light to LightStateBlinking in the objects menu, so it flashes as part of the opening demo routine. Next, we turn the light off in the NewBall() sub, for the start of each ball:
Code

Sub NewBall()
BonusCollectLight.State = 0 ' Turn off collect bonus light
End Sub

And we also add the code to turn it back to it's blinking state in our attract mode routine, that runs after the game is over.
Code

Sub AttractLights()
BonusCollectLight.State = 2
Bullet6 end Sub

Now we get the base code in for the kicker and set up the delay timer for the kicker. We put a timer in using the editor (It's on the LEFT hand side of the table), make sure the enabled checkbox is UNCHECKED, and set the interval to 500, or 1/2 a second delay before the ball is kicked back out. We also started a subroutine in the SCORE EVENT SUBROUTINES section, so in your own table, all you would have to do is point to BonusCollect() in your code. For this example, you need to add the code to enable the kicker if the light is blinking, so to do that, we used the RampLoopLeft Trigger to look for the light blinking, and turn on the kicker to collect the bonus if the light is blinking. We also added a else statement that makes sure the kicker is set to off in case the light isn't blinking, just to be on the safe side:
Code

Sub RampLoopLeft_Hit
' For Red Ramp Loop Bonus and Bonus Collect Trigger

If BonusCollectLight.State = 2 Then ' if the BonusCollectLight is BLINKING
BonusCollectKicker.Enabled = true ' Turn on the BonusCollectKicker to stop the ball
Else ' Or if light is not blinking
BonusCollectKicker.Enabled = false ' Make sure the kicker is switched OFF
End If

End Sub ' Bullet6 end of Sub RampLoopLeft_Hit

Sub BonusCollectKicker_Hit()
' This starts the bonus collect sub when made

If BonusCollectKicker.Enabled = True Then ' if the Kicker is turned "ON"
BonusCollect() ' Go to the bonus collect routine
End If

End Sub

Sub BonusCollectKickerTimer_Timer()

PlaySound"kicker" ' Play a sound
BonusCollectKicker.Kick 135,1 ' Kick the ball out
BonusCollectKickerTimer.Enabled=False ' Turn off kicker so the game will ignore it

Bullet6 end Sub

' Collect unmultiplied Bonus Value

Sub BonusCollect()

HoldBonus = Bonus ' Store Bonus Value in HoldBonus so we can store the
' bonus value to be restored back after the count
BonusTimer2.Enabled=True ' Collect Bonus routine

Bullet6 end Sub

So this code basically tells the script that if the BonusCollectLight is Blinking, when the ball triggers the RampLoopLeft trigger, it then turns on the kicker, so the ball will stop and collect the bonus by calling the BonusCollect sub. If the light is off, then ignore the kicker, and the ball will continue to travel down the red ramp as if the kicker wasn't there. Lets turn it on, and make sure the kicker works. Since we have a set of target banks, might as well use that. We also already have a key press ("C" on the keyboard) that automatically triggers all three targets, so that makes it very handy. All we have to do is turn on the BonusCollectLight and blink the light when all three drop targets are down. Just go in the RESET AND CHECKING Section, and add to the TargetsABCTimer_Timer() sub, which contains the scoring code:
Code

Sub TargetsABCTimer_Timer()

ResetTargets() ' reset the targets and
BonusCollectLight.State = 2 ' Turn on the light to collect bonus at Red Ramp BonusCollectKicker
addscore 25000 ' award 25,000 points
TargetsABCTimer.Enabled = 0 '0 = false

Bullet6 end Sub

After testing it and playing a few games, it works fine, so now is the time to get the routine to actually give out the bonus value. We need two variables, one to store the actual Bonus, so we can restore the bonus after the count, and one to store the multiplier value so we can "switch off" the multiplier when we count the bonus, and restore it back after the count is finished. If you look through the script, we already have a variable that stores the bonus, called HoldBonus (which is used so we can count the end of ball bonus by each multiplier) so we need another variable, which we will call HoldMult() So in the HoldBonus() sub, we first make sure the values are the same for the Bonus and the HoldBonus, and the Mult and HoldMult. Now we have to write the routine that scores the bonus and handles the lights. Rather than mess around modifing the main Bonus Countdown routine, because it calls the end of ball routines, we just duplicated the code and modified it for this tutorial. Just follow the rem statements, pretty much explains everything.
Code

'Collect the bonus from BonusCollectKicker

Sub BonusTimer2_Timer()
' This is the second Bonus, collected by BonusCollectKicker_Hit

x = int(bonus/10) ' Will be equal to the 10's digit
y = bonus mod 10 ' Will be equal to the 1's digit
Counted = false ' Ensure that this is set to false before we count

' We go into this if/then section if there are any lights lit in the 1k - 9k Bullet6 range.
' The highest value light will be turned off and our score will be increased
' by 1000 times for every bonus Bullet6 count. We set the variable 'counted' to true to
' make sure that we only count once per timer cycle.

if y <> 0 then ' if there are any 1k - 9k lights lit then y will not equal zero and we will proceed

select case y
case 9 ' Counts the 9k light
Light9k.state = 0:playSound"c6" ' Turns off the 9k light
case 8 ' Counts the 8k light
Light8k.state = 0:playSound"c6" ' Turns off the 8k light
case 7 ' Counts the 7k light
Light7k.state = 0:playSound"c6" ' Turns off the 7k light
case 6 ' Counts the 6k light
Light6k.state = 0:playSound"c6" ' Turns off the 6k light
case 5 ' Counts the 5k light
Light5k.state = 0:playSound"c6" ' Turns off the 5k light
case 4 ' Counts the 4k light
Light4k.state = 0:playSound"c6" ' Turns off the 4k light
case 3 ' Counts the 3k light
Light3k.state = 0:playSound"c6" ' Turns off the 3k light
case 2 ' Counts the 2k light
Light2k.state = 0:playSound"c6" ' Turns off the 2k light
case 1 ' Counts the 1k light
Light1k.state = 0:playSound"c6" ' Turns off the 1k light
Bullet6 end select

addscore 1000 ' adds the counted bonus to our score
counted = true ' We counted a 1's bonus so make sure we don't Bullet6 count a
bonus

Bullet6 end if

if x <> 0 and counted = false then ' Only count a 10's bonus if we have some and have not counted a 1's bonus

select case x
case 3 ' if both 20k Light and 10k light are on then
Light1k.state = 1 ' Turn on the 1k - 9k lights and the 10k light Off
Light2k.state = 1
Light3k.state = 1
Light4k.state = 1
Light5k.state = 1
Light6k.state = 1
Light7k.state = 1
Light8k.state = 1
Light9k.state = 1
Light10k.state = 0 ' Turn off the 10k light
case 2 ' If the 20k Light is on then
Light1k.state = 1 ' Turn on the 1k - 9k lights and the 10k light
Light2k.state = 1
Light3k.state = 1
Light4k.state = 1
Light5k.state = 1
Light6k.state = 1
Light7k.state = 1
Light8k.state = 1
Light9k.state = 1
Light10k.state = 1
Light20k.state = 0 ' Turn off the 20k light
case 1 ' if the 10k Light is on then
Light1k.state = 1 ' Turn on the 1k - 9k lights
Light2k.state = 1
Light3k.state = 1
Light4k.state = 1
Light5k.state = 1
Light6k.state = 1
Light7k.state = 1
Light8k.state = 1
Light9k.state = 1
Light10k.state = 0 ' Turn off the 10k light
Bullet6 end select

addscore 1000 ' Adds the counted bonus to our score
counted = true ' Makes sure we only Bullet6 count once per cycle
Bullet6 end if

bonus = bonus - 1 ' subtract the bonus we just counted from the total bonus

if x = 0 and y = 0 then ' We have counted all bonus
BonusCollectLight.State = 0 ' Turn BonusCollectLight off
Bonus = HoldBonus ' Add the orginal bonus value back
AddBonusLights() ' Restore the bonus lights
BonusCollectKickerTimer.Enabled=True ' Turn on the delay to kick the ball
BonusTimer2.Enabled = false ' turn off the timer

end if

End Sub ' Bullet6 end sub BonusTimer2_Timer

If you look at the bottom, we tell the script to execute the reset codes in the If Then statement. We do this to make sure that the count is finished before the ball is kicked out back into play. Since the statement calls a actual table object within it, we modified the code so we point to another sub, that handles the code to close the table objects instead...
Code

Sub BonusTimer2_Timer

if x = 0 and y = 0 then ' We have counted all bonus

Bonus = HoldBonus ' Add the orginal bonus value back
AddBonusLights() ' Restore the bonus lights
BonusTimer2.Enabled = false ' turn off the timer
BonusCollectClose ' End Routine

end if

End Sub ' Bullet6 end sub BonusTimer2_Timer

Here's the BonusCollectClose Statement. This is solely for the purpose of keeping the table coding outside of the main subroutines, and also is used to prevent the ball from kicking out before the countdown is finished.
Code

' Close BonusCollect

Sub BonusCollectClose()

BonusCollectLight.State = 0 ' Turn BonusCollectLight off
BonusCollectKickerTimer.Enabled=true ' Turn on the delay to kick the ball
End Sub

So in your table, make sure you have the BonusCollectClose routine in your table script. The sub is included within the RESET AND CHECKING Section. Here's The Final code:
Code

REM ***********************************
REM *** Bonus Collect routine ***
Rem ***********************************
'
' Based on the shivaEngine table example
'
' Tutorial by shiva
' Code by shiva, Cold1, and Spike
'
' For collecting a un-multiplied Bonus value
' and then resetting the bonus back and continue playing
' NOTE: THIS SCRIPT POINTS TO VARIABLES THAT DON"T EXIST. SEE shivaEngine FOR THE COMPLETE SCRIPT!
'
'********************************************
Rem
Rem *** General Declarations Section ***
Rem
'********************************************
Rem This is at the top of the script.

Dim x ' General use variable
Dim y ' General use variable
Dim Bonus ' Tracks the end of ball bonus
Dim HoldBonus ' Variable to store bonus for multiplier countdown
Dim Counted ' Bonus count tracker

Sub Table1_Init()

x = 0 ' Set this to a known state. Don't forget to do this prior to use.
y = 0 ' Same as for x
bonus = 1 ' We start with 1,000 for the end of ball bonus
HoldBonus = bonus ' Store HoldBonus variable to match bonus
Counted = false ' This should always be false unless we just did a bonus count

End Sub
'********************************************
Rem
Rem *** Score Event Subroutines ***
Rem
'********************************************
Rem This is the preset routine, to use, just add BonusCollect() to your code

' Collect unmultiplied Bonus Value

Sub BonusCollect()
HoldBonus = Bonus ' Store Bonus Value in HoldBonus so we can store the
' bonus value to be restored back after the Bullet6 count
BonusTimer2.Enabled=true ' Collect Bonus routine

End Sub

'*** Collect the bonus from BonusCollectKicker ***

Sub BonusTimer2_Timer()
' This is the second Bonus, collected by BonusCollectKicker_Hit

x = int(bonus/10) ' Will be equal to the 10's digit
y = bonus mod 10 ' Will be equal to the 1's digit
Counted = false ' Ensure that this is set to false before we Bullet6 count

' We go into this if/then section if there are any lights lit in the 1k - 9k range.
' The highest value light will be turned off and our score will be increased
' by 1000 times for every bonus count. We set the variable 'counted' to true to
' make sure that we only Bullet6 count once per timer cycle.

if y <> 0 then ' If there are any 1k - 9k lights lit then y will not equal zero and we will proceed

select case y
case 9 ' Counts the 9k light
Light9k.state = 0:playSound"c6" ' Turns off the 9k light
case 8 ' Counts the 8k light
Light8k.state = 0:playSound"c6" ' Turns off the 8k light
case 7 ' Counts the 7k light
Light7k.state = 0:playSound"c6" ' Turns off the 7k light
case 6 ' Counts the 6k light
Light6k.state = 0:playSound"c6" ' Turns off the 6k light
case 5 ' Counts the 5k light
Light5k.state = 0:playSound"c6" ' Turns off the 5k light
case 4 ' Counts the 4k light
Light4k.state = 0:playSound"c6" ' Turns off the 4k light
case 3 ' Counts the 3k light
Light3k.state = 0:playSound"c6" ' Turns off the 3k light
case 2 ' Counts the 2k light
Light2k.state = 0:playSound"c6" ' Turns off the 2k light
case 1 ' Counts the 1k light
Light1k.state = 0:playSound"c6" ' Turns off the 1k light
end select

addscore 1000 ' adds the counted bonus to our score
counted = true ' We counted a 1's bonus so make sure we don't count a 10's bonus

Bullet6 end if

if x <> 0 and counted = false then ' Only count a 10's bonus if we have some and have not counted a 1's bonus

select case x
case 3 ' if both 20k Light and 10k light are on then
Light1k.state = 1 ' Turn on the 1k - 9k lights and the 10k light Off
Light2k.state = 1
Light3k.state = 1
Light4k.state = 1
Light5k.state = 1
Light6k.state = 1
Light7k.state = 1
Light8k.state = 1
Light9k.state = 1
Light10k.state = 0 ' Turn off the 10k light
case 2 ' If the 20k Light is on then
Light1k.state = 1 ' Turn on the 1k - 9k lights and the 10k light
Light2k.state = 1
Light3k.state = 1
Light4k.state = 1
Light5k.state = 1
Light6k.state = 1
Light7k.state = 1
Light8k.state = 1
Light9k.state = 1
Light10k.state = 1
Light20k.state = 0 ' Turn off the 20k light
case 1 ' if the 10k Light is on then
Light1k.state = 1 ' Turn on the 1k - 9k lights
Light2k.state = 1
Light3k.state = 1
Light4k.state = 1
Light5k.state = 1
Light6k.state = 1
Light7k.state = 1
Light8k.state = 1
Light9k.state = 1
Light10k.state = 0 ' Turn off the 10k light
Bullet6 end select

addscore 1000 ' Adds the counted bonus to our score
counted = true ' Makes sure we only Bullet6 count once per cycle
Bullet6 end if

bonus = bonus - 1 ' subtract the bonus we just counted from the total bonus

if x = 0 and y = 0 then ' We have counted all bonus

Bonus = HoldBonus ' Add the orginal bonus value back
AddBonusLights() ' Restore the bonus lights
BonusTimer2.Enabled = false ' turn off the timer
BonusCollectClose ' Bullet6 end Routine

Bullet6 end if

Bullet6 end Sub ' End sub BonusTimer2_Timer

'********************************************
Rem
Rem *** HIT EVENT SECTION ***
Rem
'********************************************

Sub NewBall()
' Light control
BonusCollectLight.State = 0 ' Turn off collect bonus light

End Sub ' Bullet6 end of Sub NewBall

'********************************************

Sub RampLoopLeft_Hit
' for Red Ramp Loop Bonus and Bonus Collect Trigger

if BonusCollectLight.State = 2 Then ' If the BonusCollectLight is BLINKING
BonusCollectKicker.Enabled = True ' Turn on the BonusCollectKicker to stop the ball
else ' Or if light is not blinking
BonusCollectKicker.Enabled = False ' Make sure the kicker is switched OFF
Bullet6 end if

Bullet6 end Sub ' End of Sub RampLoopLeft_Hit

'********************************************

Sub BonusCollectKicker_Hit()
' This starts the bonus collect sub when made

If BonusCollectKicker.Enabled = True Then ' if the Kicker is turned "ON"
BonusCollect() ' Go to the bonus collect routine
End If
End Sub

'********************************************

Sub BonusCollectKickerTimer_Timer()

PlaySound"kicker" ' Play a sound
BonusCollectKicker.Kick 135,1 ' Kick the ball out
BonusCollectKickerTimer.Enabled=false ' Turn off kicker so the game will ignore it

End Sub

'********************************************
Rem
Rem *** Bullet6 reset AND CHECKING Section ***
Rem
'********************************************
' Bonus Light routine, for light control during Bonus Countdown
' Called by AddBonus Sub and by BonusCollect sub

Sub AddBonusLights()

x = Int(bonus/10) ' 10's bonus digit
y = bonus Mod 10 ' 1's bonus digit

If y = 0 Then ' Turn off the lights
Light1k.State = 0
Light2k.State = 0
Light3k.State = 0
Light4k.State = 0
Light5k.State = 0
Light6k.State = 0
Light7k.State = 0
Light8k.State = 0
Light9k.State = 0
Bullet6 end if

' This makes sure the proper light is turned on with the proper bonus
If y >= 1 Then Light1k.State = 1
If y >= 2 Then Light2k.State = 1
If y >= 3 Then Light3k.State = 1
If y >= 4 Then Light4k.State = 1
If y >= 5 Then Light5k.State = 1
If y >= 6 Then Light6k.State = 1
If y >= 7 Then Light7k.State = 1
If y >= 8 Then Light8k.State = 1
If y = 9 Then Light9k.State = 1

Light10k.State = 0
Light20k.State = 0

' This makes sure the proper "10" light is turned on with the proper bonus
if x = 1 Then Light10k.State = 1
if x = 2 Then Light20k.State = 1
if x = 3 Then ' If bonus is "30", turn on both lights
Light10k.State = 1
Light20k.State = 1
End If

End Sub ' Bullet6 end of Sub AddBonus

'********************************************
' Close BonusCollect
Sub BonusCollectClose()
BonusCollectLight.State = 0 ' Turn BonusCollectLight off
BonusCollectKickerTimer.Enabled=True ' Turn on the delay to kick the ball
Bullet6 end Sub

'********************************************
' Add this to your Attract mode to turn on light during demo.
Sub AttractLights()
BonusCollectLight.State = 2
Bullet6 end Sub

'********************************************
Rem
Rem *** Scoring Section ***
Rem
'********************************************

' *** Main Score Routine ***

Sub addscore (points) ' collect the points for doing something

if tilt = false Then ' But not if we are tilted
If gameover = False Then ' And not if the game is over
score(player) = score(player) + points ' Add the points to our score
ScoreBox(player).Text = FormatNumber(score(player), 0, -1, 0, -1) ' Display the new score
if score(player) > goal1 Then ' Check to see if we have enough for the first replay
If made1(player) = False Then ' if we do check to see if we got it already
made1(player) = true ' If we didn't then collect it
GetSpecial() ' Add 1 to our credits
End If
End If

If score(player) > goal2 Then ' Same as above except for making the second replay score
If made2(player) = false Then
made2(player) = true
GetSpecial()
Bullet6 end if
Bullet6 end if
Bullet6 end if
Bullet6 end if

Bullet6 end Sub ' End of Sub addscore

'*** Bonus Routine ***

Sub AddBonus() ' add 1k bonus to the bonus counter and change the lights
' The control routine for adding a bonus to your score
' Note the two variables, the "x" handles the 10 and 20 lights
' The "y" variable is for the 1 to 9 lights

HoldBonus = Bonus 'Holds Bonus in another variable for BonusCount by Mult
PlaySound"c6"
bonus=bonus + 1 'This increases Bonus by one
if bonus > 39 Then ' But don't go over 39k bonus
bonus = 39 ' Make sure it will stay at 39
addscore 1000 ' Award 1000 points instead
End If
AddBonusLights() 'Calls sub in RESET AND CHECKING section
End Sub

REM *** END CODE ***


Updated Jun 22, 2005 Written by shiva
 
General chit-chat
Help Users
  • No one is chatting at the moment.
    Top