ScriptVersion = "1.7L"

'*************************************************************************
'
'                           Cirqus Voltaire 
'                             Bally 1997
'
'    VPM Table by Fuseball(Ian Boffin)/wpcmame/PacDude with mods by PK
'      (See Rev History file for full credit list and table history)
'
'                   Driven by Visual PinMAME (VPinMAME)
'
'*************************************************************************

'The actual scripts are now here in Cirqus Voltaire, Bally, 1997 1.7 and 1.7L.vbs!
'The L version is WITHOUT THE LARGE MENAGERIE BALL for running the table on slow computers
 
'===========
'Yield Time
'===========
'Adjust this to change your yield time setting or disable it completely in the F6 options menu
'Yield Time Settings between 1 and 2 work well for some.  Others work better with it disabled completely
'Faster computers usually work better with little to no yield times.

Const YieldTime = 1

'================
'Timer Intervals
'================
'These can be adjusted to control the fading light speed, non fading light speed and solenoid timer intervals.
'Higher numbers generally equal slower fading speeds and light reactions, but less CPU Load.

'Solenoid Timer Interval
'- Needs to be pretty fast to properly handle events and show flashers being updated quickly.  
'- Slowing it down too much will cause lag issues (default = 1)

SolTimer.Interval = 1

'Light Control Timer Interval
'- Controls both how fast the lights are updated and how long between each stage of fading (default = 45)

LightControl.Interval = 45

'"GI" Timer Interval
'- Controls how fast the GI lights are updated relative to the emulated electronics (default = 10)

GITimer.Interval = 10

Const UseSolenoids  = True
Const UseLamps      = False   ' True not used as Fading Light System in place
Set GICallback      = GetRef("UpdateGI")
'Standard Sounds used by Driver help code
Const SSolenoidOn   = "SolenoidOn"
Const SSolenoidOff  = "SolenoidOff"
Const SFlipperOn    = "FlipperUp"
Const SFlipperOff   = "FlipperDown"
Const SCoin         = "Quarter"

'=========
'Switches
'=========
Const swBackBoxLuck     = 11 ' was swCirqusLuck
Const swWireRampEnter 	= 12
Const swStartButton 	= 13
Const swTilt		= 14
Const swLeftLoopUpper	= 15
Const swTopEddy		= 16 ' under playfield
Const swRightInlane	= 17
Const swShooterLane     = 18
Const swSlamTilt	= 21
Const swCoinDoor	= 22
Const swRightLoopUpper  = 23
Const sw24		= 24 ' always closed
Const swInnerLoopLeft   = 25
Const swLeftInlane      = 26
Const swLeftOutlane     = 27
Const swInnerLoopRight  = 28
Const swTroughEject	= 31
Const swTrough1		= 32
Const swTrough2		= 33
Const swTrough3		= 34
Const swTrough4		= 35
Const swPopperOpto	= 36
Const swWowTargeta	= 37
Const swTopTargeta	= 38
Const swLeftLane	= 41
Const swRingmasterUp    = 42
Const swRingmasterMid   = 43
Const swRingmasterDown  = 44
Const swLeftRampMade    = 45
Const swSubwayUpper     = 46
Const swSubwayMiddle    = 47
Const swLeftLoopEnter   = 48
Const swLeftSlingshot   = 51
Const swRightSlingshot  = 52
Const swUpperBumper     = 53
Const swMiddleBumper    = 54
Const swLowerBumper     = 55
Const swSkillShot       = 56
Const swRightOutlane    = 57
Const swRingNG		= 58
Const swLightTarget	= 61
Const swLockTarget 	= 62
Const swRampEnter       = 63
Const swRampMagnet      = 64
Const swRampMade        = 65
Const swRampLockLow     = 66
Const swRampLockMid     = 67
Const swRampLockHi      = 68
Const swLeftSaucer      = 71
Const swRightSaucer     = 72
'sw 73 not used
Const swBigBallRebound  = 74
Const swVoltRight       = 75
Const swVoltLeft        = 76
'sw 77 and 78 not used
'all of row 8x not used
Const swRightSpinner	= 115
Const swLeftSpinner	= 117

'==========
'Solenoids
'==========
'Handle Solenoid Events
Sub SolTimer_Timer()
	Dim ChgSol, tmp, ii
	ChgSol  = Controller.ChangedSolenoids
	If Not IsEmpty(ChgSol) Then
		For ii = 0 To UBound(ChgSol)
			tmp = SolCallback(ChgSol(ii, 0))
			If tmp <> "" Then Execute tmp & vpmTrueFalse(ChgSol(ii, 1)+1)
		Next
	End If
End Sub

Const sAutoPlungeFire      =  1
Const sBackBoxKicker       =  2
Const sLeftLoopMagnet      =  3
Const sMiddleJet           =  4
Const sRampMagnet          =  5
'Const sDiverterPower       =  6   ' not used by VP
Const sBoomUp              =  7
Const sBoomRelease         =  8
Const sTroughEject         =  9
Const sLeftSling           = 10
Const sRightSling          = 11
Const sUpperJet            = 12
Const sLowerJet            = 13
Const sLeftSaucer          = 14
Const sRightSaucer         = 15
Const sLockPost            = 16
Const fJoinCircus	   = 17
Const fRing1		   = 18
Const fRing2		   = 19
Const fRing3		   = 20
Const fRightPlayfield	   = 21
'Const fUpperRightBackBox   = 21   ' in manual for backbox
Const sMotorEnable         = 22
Const fJet		   = 23
Const fLeftPlayfield	   = 24
'Const fUpperLeftBackBox    = 24   ' in manual for backbox
Const fUpperLeftPlayfield  = 25
Const fUpperRightPlayfield = 26
'Const fLowerLeftBackBox    = 26   ' in manual for backbox
Const fRingmaster	   = 27
Const fBearPlayfield       = 28
'Const fLowerRightBackBox   = 28   ' in manual for backbox

Const sPopper              = 33
Const sDiverterHold        = 34
Const sRingmasterMagnet    = 35
Const sUpperPost           = 36
Const fNeon		   = 37
'38 not used
Const sMotorDirection      = 39   ' was 43
Const sEddyBoard           = 40   ' added

Sub LeftSlingshot_Slingshot : vpmTimer.PulseSw swLeftSlingshot : PlaySound "Sling" : End Sub
Sub RightSlingshot_Slingshot : vpmTimer.PulseSw swRightSlingshot : PlaySound "Sling" : End Sub
Sub UpperBumper_Hit : vpmTimer.PulseSw swUpperBumper : PlaySound "Bumper" : End Sub
Sub MiddleBumper_Slingshot : vpmTimer.PulseSw swMiddleBumper : PlaySound "Bumper" : End Sub
Sub LowerBumper_Hit : vpmTimer.PulseSw swLowerBumper : PlaySound "Bumper" : End Sub
Sub ShooterLane_Hit : Controller.Switch(swShooterLane) = True : End Sub
Sub ShooterLane_UnHit : Controller.Switch(swShooterLane) = False : End Sub
Sub TopTargetA_Hit : vpmTimer.PulseSw swTopTargetA : End Sub
Sub TopTargetB_Hit : vpmTimer.PulseSw swTopTargetA : End Sub
Sub WowTargetA_Hit : vpmTimer.PulseSw swWowTargetA : End Sub
Sub WowTargetB_Hit : vpmTimer.PulseSw swWowTargetA : End Sub
Sub WowTargetC_Hit : vpmTimer.PulseSw swWowTargetA : End Sub
Sub LeftLane_Hit : vpmTimer.PulseSw swLeftLane : End Sub
Sub LeftInlane_Hit : Controller.Switch(swLeftInlane) = True : End Sub
Sub LeftInlane_UnHit : Controller.Switch(swLeftInlane) = False : End Sub
Sub RightInlane_Hit : Controller.Switch(swRightInlane) = True : End Sub
Sub RightInlane_UnHit : Controller.Switch(swRightInlane) = False : End Sub
Sub LeftOutlane_Hit : Controller.Switch(swLeftOutlane) = True : End Sub
Sub LeftOutlane_UnHit : Controller.Switch(swLeftOutlane) = False : End Sub
Sub RightOutlane_Hit : Controller.Switch(swRightOutlane) = True : End Sub
Sub RightOutlane_UnHit : Controller.Switch(swRightOutlane) = False : End Sub
Sub LeftLoopEnter_Hit : Controller.Switch(swLeftLoopEnter) = True : End Sub
Sub LeftLoopEnter_UnHit : Controller.Switch(swLeftLoopEnter) = False : End Sub
Sub LeftLoopUpper_Hit : Controller.Switch(swLeftLoopUpper) = True : End Sub
Sub LeftLoopUpper_UnHit : Controller.Switch(swLeftLoopUpper) = False : End Sub
Sub RightLoopUpper_Hit : Controller.Switch(swRightLoopUpper) = True : End Sub
Sub RightLoopUpper_UnHit : Controller.Switch(swRightLoopUpper) = False : End Sub
Sub VoltRight_Hit : Controller.Switch(swVoltRight) = True : End Sub
Sub VoltLeft_Hit : Controller.Switch(swVoltLeft) = True : End Sub
Sub VoltRight_UnHit : Controller.Switch(swVoltRight) = False : End Sub
Sub VoltLeft_UnHit : Controller.Switch(swVoltLeft) = False : End Sub
Sub WireRampEnter_Hit : Controller.Switch(swWireRampEnter) = True : End Sub
Sub WireRampEnter_UnHit : Controller.Switch(swWireRampEnter) = False : End Sub
Sub InnerLoopLeft_Hit : Controller.Switch(swInnerLoopLeft) = True : End Sub
Sub InnerLoopLeft_UnHit : Controller.Switch(swInnerLoopLeft) = False : End Sub
Sub InnerLoopRight_Hit : Controller.Switch(swInnerLoopRight) = True : End Sub
Sub InnerLoopRight_UnHit : Controller.Switch(swInnerLoopRight) = False : End Sub
Sub BigBallRebound_Slingshot : vpmTimer.PulseSw swBigBallRebound : End Sub
Sub RingNG_Hit : vpmTimer.PulseSw swRingNG : End Sub
Sub LightTarget_Hit : vpmTimer.PulseSw swLightTarget : End Sub
Sub LockTarget_Hit : vpmTimer.PulseSw swLockTarget : End Sub
Sub SkillShot_Hit : vpmTimer.PulseSw swSkillShot : End Sub
Sub RampEnter_Hit : Controller.Switch(swRampEnter) = True : End Sub
Sub RampEnter_UnHit : Controller.Switch(swRampEnter) = False : End Sub
Sub RampMagnet_Hit : Controller.Switch(swRampMagnet) = True : End Sub
Sub RampMagnet_UnHit : Controller.Switch(swRampMagnet) = False : End Sub
Sub RampMade_Hit : Controller.Switch(swRampMade) = True : End Sub
Sub RampMade_UnHit : Controller.Switch(swRampMade) = False : End Sub
Sub Spinner1_Spin : vpmTimer.PulseSw swRightSpinner : End Sub
Sub Spinner2_Spin : vpmTimer.PulseSw swLeftSpinner : End Sub
Sub LeftRampMade_Hit : Controller.Switch(swLeftRampMade) = True : End Sub
Sub LeftRampMade_Unhit : Controller.Switch(swLeftRampMade) = False : End Sub
Sub LockRoll2_Hit : Controller.Switch(swRampLockMid) = True : End Sub
Sub LockRoll2_Unhit : Controller.Switch(swRampLockMid) = False : End Sub
Sub LockRoll3_Hit : Controller.Switch(swRampLockHi) = True : End Sub
Sub LockRoll3_Unhit : Controller.Switch(swRampLockHi) = False : End Sub
'Sub TroughJam_Hit : Controller.Switch(swTroughEject) = True : End Sub   ' Trigger removed
'Sub TroughJam_UnHit : Controller.Switch(swTroughEject) = False : End Sub
Sub BackBoxLuck_Hit : Controller.Switch(swBackBoxLuck) = True : PlaySound "BBell100" :  End Sub   ' added
Sub BackBoxLuck_UnHit : Controller.Switch(swBackBoxLuck) = False : End Sub   ' added
'----------------------------------------
'Have no idea how the Eddy Sensor works.
'Display is always showing it as faulty
'so we just ignore it
'----------------------------------------
Sub TopEddy1_Hit : Controller.Switch(swTopEddy) = True :End Sub
Sub TopEddy1_Unhit : Controller.Switch(swTopEddy) = False : End Sub
Sub TopEddy2_Hit : Controller.Switch(swTopEddy) = True : End Sub
Sub TopEddy2_Unhit : Controller.Switch(swTopEddy) = False : End Sub
Sub TopEddy3_Hit : Controller.Switch(swTopEddy) = True : End Sub
Sub TopEddy3_Unhit : Controller.Switch(swTopEddy) = False : End Sub

'=====================
'Solenoid definitions
'=====================
SolCallback(sLRFlipper)           = "SolFlip RightFlipper,Nothing,"
SolCallback(sLLFlipper)           = "SolFlip LeftFlipper,Nothing,"
SolCallback(sAutoPlungeFire)      = "AutoPlungeFire"
SolCallBack(sBackBoxKicker)       = "SolFlip Cannon,Nothing,"   ' was "SolCannon"
SolCallback(sDiverterHold)        = "vpmSolToggleWall LockDiverterOff,LockDiverterOn,""SolenoidOn"","   ' was vpmSolDiverter "AcrobatDiverter"
SolCallBack(sBoomUp)              = "BoomBalloonUp"
SolCallBack(sBoomRelease)         = "BoomBalloonDown"
SolCallBack(sRingmasterMagnet)    = "SolRingmasterMagnet"
SolCallBack(sUpperPost)           = "SideShowWall.IsDropped = Not "
SolCallBack(fJoinCircus)          = "SetLight 90,"   ' was "vpmFlasher Flasher17,"
SolCallBack(fRing1)               = "SetLight 91,"   ' was "vpmFlasher Flasher18,"
SolCallBack(fRing2)               = "SetLight 92,"   ' was "vpmFlasher Flasher19,"
SolCallBack(fRing3)               = "SetLight 93,"   ' was "vpmFlasher Flasher20,"
SolCallBack(fRightPlayfield)      = "Flasher21"
SolCallBack(fJet)                 = "SetLight 94,"   ' was "vpmFlasher Flasher23,"
'SolCallBack(fUpperRightBackBox)   = "SetLight 95,"
SolCallBack(fLeftPlayfield)       = "Flasher24"
'SolCallBack(fUpperLeftBackBox)    = "SetLight 96,"
SolCallBack(fUpperLeftPlayfield)  = "Flasher25"
SolCallBack(fUpperRightPlayfield) = "Flasher26"
'SolCallBack(fLowerLeftBackBox)    = "SetLight 97,"
SolCallBack(fBearPlayfield)       = "BearFlasher.IsDropped = Not "
'SolCallBack(fLowerRightBackBox)   = "SetLight 98,"
SolCallBack(fNeon)                = "NeonOn.IsDropped = Not "

Sub SolFlip(aFlip1, aFlip2, aEnabled) ' Ball Through Flipper Fix
    Dim oldSpeed
    If aEnabled Then
        PlaySound SFlipperOn : aFlip1.RotateToEnd : If Not aFlip2 Is Nothing Then aFlip2.RotateToEnd
    Else
        PlaySound SFlipperOff
        oldSpeed = aFlip1.Speed : aFlip1.Speed = 0.5
        aFlip1.RotateToStart : aFlip1.Speed = oldSpeed
        If Not aFlip2 Is Nothing Then
            oldSpeed = aFlip2.Speed : aFlip2.Speed = 0.5
            aFlip2.RotateToStart : aFlip2.Speed = oldSpeed
        End If
    End If
End Sub

Sub Flasher21(enabled) : Flash21.setvalue abs(enabled) : Flash21a.setvalue abs(enabled) : End Sub
Sub Flasher24(enabled) : Flash24.setvalue abs(enabled) : Flash24a.setvalue abs(enabled) : End Sub
Sub Flasher25(enabled) : Flash25.setvalue abs(enabled) : Flash25a.setvalue abs(enabled) : End Sub
Sub Flasher26(enabled) : Flash26.setvalue abs(enabled) : End Sub

Sub SolRelease(enabled) 
	If enabled And bsTrough.Balls > 0 Then   ' Try 3 if problem with multiple balls
		vpmTimer.PulseSw swTroughEject
		bsTrough.ExitSol_On
	End If
End Sub
	
Sub SolExit(enabled) 
	If enabled And vlLock.Balls > 2 Then   ' Try 0 if problems still
	        vpmTimer.PulseSw swLock1
 		vpmTimer.PulseSw swLock2
 		vpmTimer.PulseSw swLock3
		vlLock.ExitSol_On
	End If
End Sub

Dim bsTrough, bsPopper, bsLeftSaucer, bsRightSaucer, vlLock
Dim mechRM, mRingmasterMagnet, mLockMagnet, mJugglerMagnet
Dim cvOptions, RMHideOutBalls
Dim RomName
Dim plungerIM

'Impulse Plunger as devised by PacDude (needs to be defined before menu options in order to adjust in options)
	Const IMPowerSetting	= 25   ' 35   ' 29    ' Plunger Power (adjusted in table options, though)
	Const IMTime			= 0.5   ' Time in seconds for Full Plunge
	Set plungerIM = New cvpmImpulseP : With plungerIM
		.InitImpulseP IMPlunger, IMPowerSetting, IMTime
		.Random 0.5
		.Switch 18
'		.InitExitSnd "Plunger"
		.CreateEvents "plungerIM"
	End With

'=========================
'Set up DIP + otions menu
'=========================
Private Sub cvShowDips
	If Not IsObject(vpmDips) Then ' First time
		Set vpmDips = New cvpmDips
		With vpmDips
			.AddForm 100, 330, "CV Options Menu"
			.AddFrame 0, 190, 125, "Misc. Dips", 0, Array("W20", &H04, "W19", &H08)
			.AddFrame 0, 0, 125, "Dips By Country", &Hf0,_
				Array("USA", &H00, "USA", &Hf0, "European", &Hd0,_
				      "Export", &Ha0, "Export Alt", &H80, "France", &Hb0,_
				      "France 1", &H10, "France 2", &H30, "France 3", &H90,_
			    	  "Germany", &H20, "Spain", &He0, "UK", &Hc0)
			.AddFrameExtra 0, 240, 125, "Table Options", 0,_
				Array("Disable Flashers", &H01, "Disable GI Effects", &H02,_
				"Don't Keep Balls", &H08, "No Menu At Start", &H10,_ 
				"No Yield Time", &H20, "No Fading Light Effect", &H40)
			If Controller.Version > "01120100" Then				
				.AddFrameExtra 0, 350, 125, "ROM Version", &H04,_
                	Array("1.4  (Arcade)", 0, "2.0H (Home)", &H04)
'			 		 Array("1.0", 0, "1.1", 0, "1.3", 0, "1.4  (Arcade)", 0, "2.0H (Home)", &H04)
			End If
		End With
	End If
	cvOptions = vpmDips.ViewDipsExtra(cvOptions)
	cvSetOptions :	SaveValue "CV","Options",cvOptions
End Sub
Set vpmShowDips = GetRef("cvShowDips")

'===============================
'Handle CV Options (except ROM)
'===============================
Dim Menu_At_Start : Menu_At_Start = True
Dim No_Yield : No_Yield = False
Dim Fading : Fading = True

Sub cvSetOptions
	If cvOptions And &H01 Then
		Controller.SolMask(0) = &Hf020ffff   ' no flashers
		Controller.SolMask(1) = &Hffffffef   ' no flashers
	Else
		Controller.SolMask(0) = &Hffffffff
		Controller.SolMask(1) = &Hffffffff
	End If
	If cvOptions And &H02 Then GICallback = Empty Else Set GICallback = GetRef("UpdateGI")
	If cvOptions And &H10 Then Menu_At_Start = False Else Menu_At_Start = True
	If cvOptions And &H20 Then No_Yield = True Else No_Yield = False
	If cvOptions And &H40 Then Fading = False Else Fading = True
End Sub

'=================
'Initialize table
'=================
Sub CV_Init
	vpmInit Me : If Controller.Version >= "01200000" Then Me.YieldTime = YieldTime
	randomize
'    SaveValue "CV","Options","" : Exit Sub  ' This will clear your Registry settings if uncommented
	cvOptions = CInt("0" & LoadValue("CV","Options")) : cvSetOptions
	If Menu_At_Start = True Then CvShowDips
	With Controller
		RomName = Array("cv_14", "cv_20h")(Sgn(cvOptions And &H04))
'   	 RomName = Array("cv_10", "cv_11", "cv_13", "cv_14", "cv_20h")(Sgn(cvOptions And &H04))
		.GameName = RomName
		.SplashInfoLine = "Cirqus Voltaire, Bally, 1997" & vbNewLine & "Table Design: Eric Priepke / Ian Boffin / John A Popadiuk / PD / PK" & vbNewLine & "Scripting: Mike Pollmann / Ian Boffin / wpcmame / PD / PK"
		.HandleKeyboard = False
		.ShowTitle = False : .ShowFrame = False : .ShowDMDOnly = True
		.HandleMechanics = 0
		.Games(RomName).Settings.Value("ddraw")=1   ' On by default
        .Games(RomName).Settings.Value("waitvsync")=0   ' Off by default. Requires ddraw
        .Games(RomName).Settings.Value("triplebuffer")=0   ' Off by default. Requires ddraw & no window
'        .Games(RomName).Settings.Value("synclevel")=0   ' Adjust in VPinMAME
        .Games(RomName).Settings.Value("throttle")=1   ' On by default
        .Games(RomName).Settings.Value("autoframeskip")=1   ' On by default
        .Games(RomName).Settings.Value("frameskip")=3   ' eg 3 frames in 12 skipped. 0 by default
        .Games(RomName).Settings.Value("samples")=0   ' On by default        
        .Games(RomName).Settings.Value("resamplefilter")=1   ' On by default
		On Error Resume Next
			.Run : If Err Then MsgBox Err.Description
		On Error Goto 0
	End With
	' Nudging
	vpmNudge.TiltSwitch = swTilt
	vpmNudge.Sensitivity = 5
	
	' Sets up ballstacks
	Set bsTrough = New cvpmBallStack : With bsTrough
		.InitSw 0,swTrough1,swTrough2,swTrough3,swTrough4,0,0,0
		.InitKick TroughEject,100,2
		.InitExitSnd "Release", "Solenoid"
		.InitAddSnd "Outhole"   
		.Balls = 4
		.CreateEvents "bsTrough", Outhole
		.IsTrough = True ' Added balls (B key) goes here
	End With
	SolCallback(sTroughEject) = "SolRelease"

	Set bsLeftSaucer = New cvpmBallStack : With bsLeftSaucer
    	.InitSaucer	LeftSaucer, swLeftSaucer, 45, 5
		.InitExitSnd "Saucer", "Saucer"
		.CreateEvents "bsLeftSaucer",0
	End With
	SolCallBack(sLeftSaucer) = "bsLeftSaucer.SolOut"

	Set bsRightSaucer = New cvpmBallStack : With bsRightSaucer
    	.InitSaucer	RightSaucer, swRightSaucer, 150, 5
		.InitExitSnd "Saucer", "Saucer"
		.CreateEvents "bsRightSaucer",0
	End With
	SolCallBack(sRightSaucer) = "bsRightSaucer.SolOut"

	Set bsPopper = New cvpmBallStack : With bsPopper
		.InitSw 0,swPopperOpto,0,0,0,0,0,0
		.InitKick UpperReEntry, 290, 15
		.InitExitSnd "Solenoid", "Solenoid"
		.KickForceVar = 3 : .KickAngleVar = 10
		.KickBalls = 2
	End With
	SolCallBack(sPopper) = "bsPopper.SolOut"

	Set mJugglerMagnet = New cvpmMagnet : With mJugglerMagnet
		.InitMagnet JugglerMagnet, 35 ' 25 ' 20
		.Solenoid = sLeftLoopMagnet
'  		 .GrabCenter = True  ' added
        .Size = 125  ' added 
		.CreateEvents "mJugglerMagnet"
	End With

	Set mLockMagnet = New cvpmMagnet : With mLockMagnet
		.InitMagnet LockMagnet, 35 ' 32
		.Solenoid = sRampMagnet
        .Size = 125 ' added
		.CreateEvents "mLockMagnet"
	End With

	Set mRingmasterMagnet = New cvpmMagnet : With mRingmasterMagnet
		.InitMagnet RingmasterMagnet, 20 ' 18.9
        .Size = 100  ' added
		.CreateEvents "mRingmasterMagnet"
	End With
	
	Set vlLock = New cvpmVLock : With vlLock
		.InitVLock Array(lockRoll1, lockRoll2, lockRoll3), Array(Lock1,Lock2,Lock3),_
		           Array(swRampLockLow, swRampLockMid, swRampLockHi)
		.InitSnd "Solenoid", "Solenoid"
		.CreateEvents "vlLock"
	End With
	SolCallback(sLockPost) = "vlLock.SolExit"
	
	vpmSolWall colRM, False, True
	Set mechRM = New cvpmMech : With mechRM
     	.Sol1 = sMotorEnable : .Sol2 = sMotorDirection
     	.MType = vpmMechLinear + vpmMechReverse + vpmMechOneDirSol + vpmMechLengthSw
     	.Length	= 128 : .Steps = colRM.Count - 1
     	.AddSw swRingmasterDown, 0,4
     	.AddSw swRingmasterMid, 96,100 ' 2/3 up   ' was 92,96
     	.AddSw swRingmasterUp, 127,131   ' was 123,127
'    	 .CallBack = GetRef("updateRM")  ' Called instead in the InitMotor Timer to fix motor bug
'    	 .Start                          ' ------
	End With
	If (cvOptions And &H08) = 0 Then cvLoadBalls 4
	
	BackBallKicker.CreateBall.Color = RGB (225,175,50)   ' light orange
	BackBallKicker.Kick 260,5
	BackBallKicker.Enabled = False

' Init solenoid events with walls
    vpmDoSolCallback sDiverterHold, False
	vpmDoSolCallback fBearPlayfield, False
	vpmDoSolCallback fNeon, False
	vpmDoSolCallback sBoomRelease, True
	vpmDoSolCallback sUpperPost, True
	Controller.Switch(22) = False	' Coin door Opened (needed for motor bug in Vpinmame)
	MotorInit.Enabled = True  ' Part of motor bug fix
End Sub

Sub CV_Exit
	cvSaveBalls
End Sub

'=========================
'Save/load ball positions
'=========================
Function cvLoadBallHelp(aName,aBalls)
	' Dim tmp : tmp = CInt("0" & LoadValue("CV",aName)) ' Changed to
    Dim tmp: tmp = ("0" & (LoadValue("CV",aName)))
    If IsNumeric(tmp) Then : tmp = CInt(tmp) : Else : tmp = 0 : End If
	If tmp > aBalls Then tmp = aBalls : aBalls = 0 Else aBalls = aBalls - tmp
	cvLoadBallHelp = tmp
End Function
Sub cvLoadBalls(ByVal aBalls)
	bsPopper.Balls      = cvLoadBallHelp("Popper",aBalls)
	bsLeftSaucer.Balls  = cvLoadBallHelp("LJuggler",aBalls)
	bsRightSaucer.Balls = cvLoadBallHelp("RJuggler",aBalls)
	vlLock.Balls        = cvLoadBallHelp("Lock",aBalls)
	bsTrough.Balls = aBalls
End Sub
Sub cvSaveBalls
	SaveValue "CV","Popper",   bsPopper.balls
	SaveValue "CV","LJuggler", bsLeftSaucer.balls
	SaveValue "CV","RJuggler", bsRightSaucer.balls
	SaveValue "CV","Lock",     vlLock.balls
End Sub

'==================
'Keyboard handlers
'==================
Sub CV_KeyUp(ByVal keycode)
	If KeyUpHandler(keycode) Then Exit Sub
    If keycode = PlungerKey Then Plunger.Fire : PlungerIM.Fire : PlaySound "Plunger"
End Sub
Sub CV_KeyDown(ByVal keycode)
	If KeyDownHandler(keycode) Then Exit Sub
	If keycode = PlungerKey Then Plunger.PullBack : PlungerIM.Pullback
'    If keycode = 46 Then MenagerieBallColor = MenagerieBallColor + 1   ' Press 'C' key to change 'Wild Ball' colour
'    If MenagerieBallColor = 6 Then MenagerieBallColor = 0
'    ChangeColor
'    Ball1.Color = BallColor
'    Ball2.Color = BallColor
'    Ball3.Color = BallColor
'    Ball4.Color = BallColor
End Sub

'================
'RM mech handler
'================
Sub MotorInit_Timer()
	MotorInit.Enabled = False
	Controller.Switch(22) = True	' Coin door closed - fixes dead motor bug
	With mechRM	.CallBack = GetRef("updateRM") : .Start : End With
	MotorInit.Interval = 100
End Sub

Dim InvisiBallFlag : InvisiBallFlag = False
Sub updateRM(aCurrPos, aSpeed, aLastPos)
	Dim tmp
	' Activate hideout kicker as when the RM starts moving
	RMHideOut1.Enabled = aCurrPos > 1
	RMHideOut2.Enabled = aCurrPos > 1
	' Addition to prevent ball traps next to raised ringmaster (from racerxme)
    BlockWall1.IsDropped = Not aCurrPos > 1
    BlockWall2.IsDropped = Not aCurrPos > 1
    ' Enable RM trough kickers when at the top position - 1
	If aCurrPos >= (colRM.Count - 2) Then
		vpmSolToggleObj colRMTrough, Nothing, False, True
		' Are there any balls in the hideout?
		If RMHideOutBalls And &H01 Then SubWayHandler RMHideOut1, swSubwayMiddle
		If RMHideOutBalls And &H02 Then SubWayHandler RMHideOut2, swSubwayMiddle
		RMHideOutBalls = &H04
	Else
		vpmSolToggleObj colRMTrough, Nothing, False, False
	End If
	colRM(aLastPos).IsDropped = True
	' Move balls on top up/or down when RM moves
	With colRM(aCurrPos)
		.IsDropped = False
		For Each tmp In mRingmasterMagnet.balls : tmp.Z = .HeightTop+25 : Next
	End With
	' Coin door closed - fixes dead motor bug
	Controller.Switch(22) = True
	' Adjust invisible height here
	If aCurrPos > 10 Then : InvisiBallFlag = True : Else : InvisiBallFlag = False : End If
End Sub

Sub RMHideOut1_Hit
	If RMHideOutBalls And &H04 Then
		SubWayHandler Me, swSubwayMiddle
	Else
		RMHideOutBalls = RMHideOutBalls Or &H01
	End If
End Sub

Sub RMHideOut2_Hit
	If RMHideOutBalls And &H04 Then
	    SubWayHandler Me, swSubwayMiddle
	Else
	    RMHideOutBalls = RMHideOutBalls Or &H02
	End If
End Sub

'============================
'Release balls on Ringmaster
'============================
Sub SolRingmasterMagnet(enabled)
	Dim ball, dir, speed
	mRingmasterMagnet.MagnetOn = enabled
	If Not enabled Then   ' magnet turned off send away in random direction
		For Each ball In mRingmasterMagnet.balls
'			 dir = 3.14 : speed = 5   ' test hideout
			dir = Rnd*6.28 : speed = 4+Rnd*8   ' speed from 3+Rnd*10
			ball.VelX = speed * Sin(dir) : ball.VelY = speed * Cos(dir)
			mRingmasterMagnet.Removeball ball
		Next
	End If
End Sub

Sub colRM_Hit(idx) : vpmTimer.PulseSw swTopTargetA : End Sub

'====================================
'Move Boom! Balloon bumper up & down 
'====================================
Dim BoomWalls : BoomWalls = Array(MiddleBumper,MiddleBumper2,Wall65,Wall66,Wall81,Wall198,Wall199,Wall204,Wall205)
Sub BoomBalloonUp(enabled)
	If enabled Then vpmSolWall BoomWalls, False, False : PlaySound "Solenoid"
End Sub

Sub BoomBalloonDown(enabled)
	If enabled Then vpmSolWall BoomWalls, "Klick", True 
End Sub

'===================
'Handle AutoPlunger
'===================
Sub AutoPlungeFire(enabled)
	If Enabled Then
		vpmTimer.AddTimer 500, "Plunger.Fire : PlungerIM.Fire : Plunger.PullSpeed = " & Plunger.PullSpeed & "'"   ' 50
		Plunger.PullSpeed = 1000 : Plunger.Pullback : PlungerIM.Pullback : PlaySound "Kick"   ' 2000
	End If
End Sub

'==============
'Handle Subway
'==============
'Ringmaster
Sub colRMTrough_Hit(idx) : SubwayHandler Me(idx), swSubwayMiddle : End Sub
'Side Show (should this also trigger swSubwayMiddle?)
Sub colSSTrough_Hit(idx) : SubwayHandler Me(idx), swSubwayUpper : End Sub

Sub SubwayHandler(aKick, aSwNo)
	aKick.Destroyball : PlaySound "SubWay"
	vpmTimer.PulseSwitch aSwNo, 2000, "bsPopper.AddBall 0'"
End Sub

'===============================================================
'Let's hope someone can come up with a clever backbox animation
'for the cannon. For now it is just random luck
'===============================================================
Sub BackBoxKicker(enabled)   ' was SolCannon(enabled)
	If enabled Then
		PlaySound "Solenoid"
		If Rnd < 0.2 Then vpmTimer.PulseSwitch swBackBoxLuck,1000,0    ' was swCircusLuck
	End If
End Sub

'=========================================
'Menagerie Ball (Wild Ball)
'Create it in the outhole and 
'move it to the cage
'=========================================
'With additional code for large Menagerie 
'Ball - compiled by Pinball Ken from code 
'and graphics by nicolas.b and Simeon and 
'ideas from scapino
'-----------------------------------------
'Dim MenagerieBall
'Dim Ball1, Ball2, Ball3, Ball4 
'Dim XPos, YPos
'Dim ZOffset, XOffset
'Dim XCenter, Height
'Dim MenagerieBallColor
'Dim BallColor
'
'Sub Outhole_Init
'	XCenter = 500   ' Table Width /2
'	Height = 2255
'End Sub
'
'Sub Outhole_Init
'	Set MenagerieBall = Me.Createball : Me.Kick 0,0
'	Set Ball1 = Kicker1.CreateBall
'	Set Ball2 = Kicker2.CreateBall
'	Set Ball3 = Kicker3.CreateBall
'	Set Ball4 = Kicker4.CreateBall
'	MenagerieBallColor = 2   ' Sets the initial ball color to green
'	ChangeColor
'	With MenagerieBall
'		 .Image = "BlankBall"
'		 .X = CaptiveTrigger.X : .Y = CaptiveTrigger.Y   ' Moves ball to the cage
'	End With
'	With Ball1
'		 .Image = "MenagerieBall1"
'	End With
'       With Ball2
'		 .Image = "MenagerieBall2"
'	End With  
'       With Ball3
'		 .Image = "MenagerieBall3"
'	End With
'	With Ball4
'		 .Image = "MenagerieBall4"
'	End With
'	Ball1.Color = BallColor
'       Ball2.Color = BallColor
'       Ball3.Color = BallColor
'       Ball4.Color = BallColor
'End Sub
'
'Sub ChangeColor()
' select case (MenagerieBallColor)
' Case 0: 'white
'	BallColor = RGB (225,225,225)
' Case 1: 'red 
'	BallColor = RGB (225,0,0)
' Case 2: 'green
'	BallColor = RGB (0,150,75)
' Case 3: 'yellow 
'	BallColor = RGB (225,225,0)
' Case 4: 'blue 
'	BallColor = RGB (0,0,225)
' Case 5: 'orange
'	BallColor = RGB (225,112,0)
' Case Else   ' Should never happen, optional for demo 
' End Select 
'End Sub
'
'Sub WildBall_Timer()
'	DrawWildBall
'End Sub
'
'Sub DrawWildBall
'	XPos = MenagerieBall.X
'	YPos = MenagerieBall.Y
'	ZOffset = ((Height-YPos)/100)+3
'	XOffset = -(((XCenter-XPos)/100)*2.5)/(ZOffset/10)
'	
'	Ball1.Z = 105+ZOffset
'	Ball1.X = XPos-25+XOffset
'	Ball1.Y = YPos-25
'	
'       Ball2.Z = 105+ZOffset
'	Ball2.X = XPos+25+XOffset
'	Ball2.Y = YPos-25
'	
'	Ball3.Z = 70   ' To respond correctly it needs to be 70>
'	Ball3.X = XPos+25
'	Ball3.Y = YPos+25
'	
'       Ball4.Z = 70
'	Ball4.X = XPos-25
'	Ball4.Y = YPos+25
'End Sub
''-----------------------
'Keeps ball in the cage
'-----------------------
'Sub CaptiveTrigger_Unhit
'	Dim Dist, Dot, dX, dY
'	If Not ActiveBall Is MenagerieBall Then Exit Sub
'	With ActiveBall
'		dX = (.X-Me.X)/Me.Radius
'		dY = (.Y-Me.Y)/Me.Radius
'		Dot = .VelX*dX+.VelY*dY
'		.VelX = (.VelX-Dot*dX*2)/1.25   ' Use 1.2 to 1.5 for bounciness of ball
'		.VelY = (.VelY-Dot*dY*2)/1.25
'	End With
'End Sub
'--------------------------------
'Sometimes the ball slips out.
'Uses second trigger to catch it
'--------------------------------
'Sub CaptiveHelp_Unhit
'	If ActiveBall Is MenagerieBall Then
'		With ActiveBall
'			.X = Me.X : .Y = Me.Y : .VelX = 0 : .VelY = 0
'		End With
'	End If
'End Sub

'==========================================
'Slow down balls at ramp ends if necessary
'==========================================
Sub SlowRightRamp_Hit
	With Activeball : .VelX=-2 : .VelY=1 : End With : PlaySound "RampEnd"
End Sub
Sub SlowLeftRamp_Hit
	With Activeball : .VelX=2 : .VelY=1 : End With : PlaySound "RampEnd"
End Sub
Sub SlowMidRamp_Hit : PlaySound "RampEnd" : End Sub

'===========
'GI Strings
'===========
Sub GITimer_Timer()
	Dim ChgGI, ii
	If isObject(GICallback) Then ChgGI = Controller.ChangedGIStrings
	If Not IsEmpty(ChgGI) Then
		For ii = 0 To UBound(ChgGI)
			GICallback ChgGI(ii, 0), CBool(ChgGI(ii, 1))
		Next
	End If
End Sub

Sub UpdateGI(no, enabled)
	Select Case no
		Case 0   ' GI line 1 (left playfield)
			vpmSolWall Array(rightslingGIon,rightlaneGIon,rightbankGIon), False, Not enabled
                        LeftSlingBulb1.state = Abs(enabled)
                        LeftSlingBulb2.state = Abs(enabled)
			LeftInLaneBulb1.state = Abs(enabled)
			LeftInLaneBulb2.state = Abs(enabled)
		Case 1	 ' GI line 2 (middle playfield)
			vpmSolWall Array(collaron,skillGIon,TopMidGIon), False, Not enabled
		Case 2	 ' GI line 3 (right playfield)
			vpmSolWall Array(leftslingshotGIon,leftreturnGIon,leftbankGIon,lefttopGIon,JugglerGIon,JugglerGIon2), False, Not enabled
                        RightSlingBulb1.state = Abs(enabled)
                        RightSlingBulb2.state = Abs(enabled)
			RightInLaneBulb1.state = Abs(enabled)
			RightInLaneBulb2.state = Abs(enabled)
	        'Case 3  ' GI line 4 (backbox 1)

	        'Case 4  ' GI line 5 (backbox 2)
	    
	End Select
End Sub

Const PD_LightSystemVersion = 5.1

'==========================================================
'Light Control (Featuring the PD V5.1 Fading Light System)
'==========================================================
'
'       See the tutorial table (should be available at http://www.shivasite.com ) to see examples of how all the
'       lights work plus handy reference sheets and more.
'
'Note: The "UpdateLights()" Sub is the only USER defined part of the system
'      (other than the timer interval and fade variable)
'      The rest appends to the end of the script (or could be adapted to the VBS core)
'
'
'How To Use:
'
'     -You will need to create a Timer on the table called either "LightControl" (for VPinmame tables) or
'      "LightControlO" (for original type tables).  45 is a good interval setting to start at.  You can either
'      change it directly on the timer or include a line in the script like:
'   
'      LightControl.Interval = 45
'                OR
'      LightControlO.Interval = 45
'
'      The interval controls the fading speed and how fast the lights are updated. "UseLights" should be turned off
'      in the script in VPM tables (referring to the regular VBS light system, if you're using it).  
'
'
'      Copy the CORE code marked below over to the table script OR set the table to load the
'      PD_LightSystem.vbs file (which must be in the same directory as the table)
'      using this sub-routine (adjust the 5.1 version in the future to whatever version of the system you're using) and
'      the call shown: 
'
'LoadPDLightSys "PD_LightSystem.vbs" , 5.1
'
'Sub LoadPDLightSys(VBSfile,VBSver)
'	On Error Resume Next
'	ExecuteGlobal GetTextFile(VBSfile)
'	If Err or PD_LightSystemVersion < VBSver Then MsgBox "Unable to open PD_LightSystem.vbs version " & VBSver & ". Ensure that it is in the same folder as this table and is the version indicated. " & vbNewLine & "Table Error:" & vbNewLine & Err.Description
'End Sub
'
'     - You use a handler call defined below in the core area to call your lights (e.g. "FadeL" for fading lights or
'       "aFadeL" for auto-label fading lights) and follow its format in the "UpdateLights" sub.  
'       Note that the auto-labeling calls shorten the amount of typing you'll need to do in the update sub
'       so that you simply type "aFadeL 11, Light11" to fade the Light11 set of light objects whereas using
'       the regular "FadeL" call will need: "FadeL 11, Light11a, Light11b, Light11, Light11off" to function.
'       The primary reason you would want to choose to NOT use auto-labeling is that it slows the light handling down
'       quite a bit.  Light handling is faster than standard VBS lights normally (with or without fade), but using 
'       auto-labeling slows it down well below standard light handling speeds.  Convenience comes at a price due to the
'       real-time processing needed to generate the extra object names automatically.  These "a" calls only apply to 
'       fading light and wall handlers.  The reel and 2-state handlers already only require 2 arguments per call.
'
'       The basic light format:
'
'        See the handler inputs for each system, but in general, you use the handler name, followed by a space, then
'        the light number from the pinball system in question, followed by another comma.  Next it's either the "ON"
'        state for the auto-label handlers, reel handlers and 2-state non-fading handlers 
'        *OR* "a,b,on,off" (for lights) OR "a,b,on" (for walls).
'  
'        Regardless of whether you use the auto-labeling or not, you'll need to have the objects in question on the table.
'        Auto-labeling only generates the long-form internally for you; it doesn't remove the need for the other objects.
'
'        Thus, regardless of whether you type "aFadeL 11,Light11" or "FadeL 11,Light11a,Light11b,Light11,Light11off" you'll
'        still need Light11, Light11a, Light11b and Light11off on the table
'        (where Light11off is the OFF color, Light11 is the ON color, Light11a is the dim color and Light11b is a step 
'         brighter than a but below the ON level).  
'         
'         Likewise for walls, the playfield is the OFF color and you'll need to
'         create additional playfields that are lit at varying levels to generate mapped walls for Light11, Light11a and 
'         Light11b (there is not light11off for walls as the playfield is the off state).  
'     
'         Reels contain the states in frames and should be generated in the following order: Off/On/DimA/DimB
'         Reel calls will work with only 2 frames as well as 4 frames. Just make sure your reels are set up propery.
' 
'         Non-Fade Handlers are to have permanant non-fading lights on the table (e.g. pop bumpers, led lights, etc.)
' 

'        Again, the primary object "ObjectName" (e.g. LightName) is the "FULL ON" state of the light or wall (or reel name).
'        Level A is the dimmest level of ON.  
'        Level B is the next brightest Level above A, but below the FULL ON state.         
'        Off (light objects only) is the light that defines the color for the "OFF" condition
'
'    - Thus if you wanted light 11 to fade using light objects in VP you would need to create 
'      Light11, Light11a, Light11b and Light11off in the table and set their colors to appropriate levels.
'      In the "UpdateLights()" sub, you'd call it with:
'      aFadeL 11, Light11   <= for auto-handling
'             or
'      FadeL 11, Light11a,Light11b,Light11,Light11off    <= for normal (fast) handling 
'
'    - Likewise, wall lights in VP would need walls for Light11, Light11a and Light11b (using 3 playfields
'      with appropriate lighting plus the regular playfield as the "OFF" state). 
'      [aFadeW, Light11] versus [FadeW, Light11a,Light11b,Light11] (minus the brackets)
'
'    - Reels would need 4 frames using the folowing sequential order (OFF, ON, Dim, Semi-Bright). [FadeR 11, Light11]
'
'    - There are handlers for 2-state lights and on/off only lights (such as pop bumpers or typical VP lights) as well.  
'    - Note also that more handlers for more situations could easily be created and added as more sub calls
'
'    - The 'Fading' variable controls whether lights will fade or just turn on and off.  You can call it from an option
'      menu or just use it in the script.  Note that with fading off it still uses the brighter "off" states for all lights.
'    - The Sub Call "AllLightsOff" will cause all lights to turn off momentarily.  It can be combined with disabling the
'      timer in the script (e.g. as a menu option) to turn off all lights until reeanbled.
'
'    Note that if you use "multiple lights" for one light number in a fade handler, you will need to use the
'    speical "m" version for all the calls except the last one in the series which should use the regular call to terminate
'    it. Otherwise, the lights won't operate correctly. This applies across object types.
'    For example, to call 4 lights using 3 different handlers here for light 11, it would look like this:
'        aFadeLm 11, Light11
'        aFadeLm 11, AltLight11
'        aFadeWm 11, WallLight11
'        FadeR  11, ReelLight11
'    Note that FadeR does not have the "m" in it as it's the last call in the series.  Again, if you only have one
'    light per light number, you don't need the the "m" calls.  The "m" calls are in both auto-label and normal calls.
'
'    To handle GI Lights or Flashers, you'll need to assign values to some unused positions in the lightnum array.
'    Included in the system is a sub call to make this very simple.  It's called "SetLight" and uses the format 
'    of "SetLight (light_number),(value)".
'
'    For example:  If you have have the SolCallBack below, you would assign it as follows:
'    (Note: that 100 is assumed to be an unused value; you would assign a different number above the normal light limit 
'     for that system.  Anything above 88 would be ok for Williams WCS system, for example.  It would have to be above
'     128 for Capcom, etc.  There are currently 150 spots in the array to choose from).
'     The solenoid number 28 is arbitrary (depends on system's flasher solenoid values)
'
'(Simple One Step Method)
'
'SolCallBack(28) = "SetLight 100,"
'
'    OR
'
'(Longform Method)
'
'SolCallBack(28) = "FlashX"
'
'Sub FlashX(enabled)
'	SetLight 100, enabled
'End Sub
'
'You would then use a handler such as FadeL for light number 100 as normal in the UpdateLights sub, depending
'on the type of light object used.  Here we assume regular lights faded with the FadeL call:
'(e.g.)
'
'FadeL 100, FlasherXa, FlasherXb, FlasherX, FlasherXoff
'
'GI lights using the system should be assigned and handled the same way.
'
'ORIGINAL TABLE ADDED NOTES:
'
'Note that on an original table you would use 1 for ON (or "true" or "lighton") and 0 for OFF (or "false" or "lightoff")
'instead of "enabled" to assign lamp values.  Remember, original tables use the "LightControlO" timer (O at the end),
'not the "LightControl" timer (no "O" and the end).
'
'IMPORTANT:
'----------
'If you want to use VP's Light Sequencer with an original table and still have fading lights in it, you will need to use
'the "SetLight" command provided here to assign the value of a control light to the array.  This means creating a set
'of lights that you will control directly in your script (as if they were regular lights), setting up the light sequencer
'and assigning those lights to the control array.  This should be done in the UpdateLights array prior to calling any
'fading light handlers (so the values are updated first).  The control lights should go below the lockbar area of the
'table so as not to be visible.  They should be regular light objects, regardless if the ones on the table are walls or
'reels.  I suggest labeling them with a "z" at the end.  
'
'Example:
'If you had Light10a,Light10b,Light10 and Light10off on the table as a fading light set, you would set the control 
'light below the lockbar area and label it Light10z.  To control that light, you just change it like a normal VP light
'(e.g. Light10z.state = 1 or Light10z.state = 0) (or use true / fase OR lighton / lightoff instead of 1 and 0).  
'In the UpdateLights sub, you would then do this (for a set of regular lights):
'
'Sub UpdateLights()
'SetLight 10, Light10z.state
'FadeL 10, Light10a,Light10b,Light10,Light10off
'End Sub
'
'Note that an example of this is techniuqe is also shown the LightTutorial table.
'

'------------------
'UPDATE LIGHTS Sub
'------------------
'This is the primary Sub you set up in the table to handle the lights.
 
'Sub UpdateLights()
'Light Control (Sub Calls to Fade Various Light Handler Sets defined below)
'(e.g.) 
'On Error Resume Next  ' Force lights to process even if there are labeling errors, etc.
rem aFadeL 11,Light11  '(Light)
rem aFadeW 12,Wall12   '(Wall)
rem FadeR 13,Reel13    '(Reel)
'etc.
'End Sub

Sub UpdateLights()
On Error Resume Next  ' Force lights to process even if there are labeling errors, etc.
FadeL 11, Light11a,Light11b,Light11,Light11off
FadeL 12, Light12a,Light12b,Light12,Light12off
FadeL 13, Light13a,Light13b,Light13,Light13off
FadeL 14, Light14a,Light14b,Light14,Light14off
FadeL 15, Light15a,Light15b,Light15,Light15off
FadeL 16, Light16a,Light16b,Light16,Light16off
FadeL 17, Light17a,Light17b,Light17,Light17off
FadeL 18, Light18a,Light18b,Light18,Light18off
FadeL 21, Light21a,Light21b,Light21,Light21off
FadeL 22, Light22a,Light22b,Light22,Light22off
FadeL 23, Light23a,Light23b,Light23,Light23off
FadeL 24, Light24a,Light24b,Light24,Light24off
FadeL 25, Light25a,Light25b,Light25,Light25off
FadeL 26, Light26a,Light26b,Light26,Light26off
FadeL 27, Light27a,Light27b,Light27,Light27off
FadeL 28, Light28a,Light28b,Light28,Light28off
FadeL 31, Light31a,Light31b,Light31,Light31off
FadeL 32, Light32a,Light32b,Light32,Light32off
FadeL 33, Light33a,Light33b,Light33,Light33off
FadeL 34, Light34a,Light34b,Light34,Light34off
FadeL 35, Light35a,Light35b,Light35,Light35off
FadeL 36, Light36a,Light36b,Light36,Light36off
FadeL 37, Light37a,Light37b,Light37,Light37off
FadeL 38, Light38a,Light38b,Light38,Light38off
FadeL 39, Light39a,Light39b,Light39,Light39off
FadeL 41, Light41a,Light41b,Light41,Light41off
FadeL 42, Light42a,Light42b,Light42,Light42off
FadeL 43, Light43a,Light43b,Light43,Light43off
FadeL 44, Light44a,Light44b,Light44,Light44off
FadeL 45, Light45a,Light45b,Light45,Light45off
FadeL 46, Light46a,Light46b,Light46,Light46off
FadeL 47, Light47a,Light47b,Light47,Light47off
FadeL 48, Light48a,Light48b,Light48,Light48off
FadeL 51, Light51a,Light51b,Light51,Light51off
FadeL 52, Light52a,Light52b,Light52,Light52off
FadeL 53, Light53a,Light53b,Light53,Light53off
FadeL 54, Light54a,Light54b,Light54,Light54off
FadeL 55, Light55a,Light55b,Light55,Light55off
FadeL 56, Light56a,Light56b,Light56,Light56off
FadeL 57, Light57a,Light57b,Light57,Light57off
FadeL 58, Light58a,Light58b,Light58,Light58off
FadeL 61, Light61a,Light61b,Light61,Light61off
FadeL 62, Light62a,Light62b,Light62,Light62off
FadeL 63, Light63a,Light63b,Light63,Light63off
FadeL 64, Light64a,Light64b,Light64,Light64off
FadeL 65, Light65a,Light65b,Light65,Light65off
FadeL 66, Light66a,Light66b,Light66,Light66off
FadeL 67, Light67a,Light67b,Light67,Light67off
FadeL 68, Light68a,Light68b,Light68,Light68off
FadeL 71, Light71a,Light71b,Light71,Light71off
FadeL 72, Light72a,Light72b,Light72,Light72off
FadeL 73, Light73a,Light73b,Light73,Light73off
FadeL 74, Light74a,Light74b,Light74,Light74off
FadeL 75, Light75a,Light75b,Light75,Light75off
FadeL 76, Light76a,Light76b,Light76,Light76off
FadeL 77, Light77a,Light77b,Light77,Light77off
FadeL 78, Light78a,Light78b,Light78,Light78off
FadeL 81, Light81a,Light81b,Light81,Light81off
NFade 82, UpperBumper
' NFade 83, Light83
NFade 84, LowerBumper
FadeL 85, Light85a,Light85b,Light85,Light85off
FadeL 86, Light86a,Light86b,Light86,Light86off
FadeL 87, Light87a,Light87b,Light87,Light87off
FadeL 88, Light88a,Light88b,Light88,Light88off
'Fading Flashers
FadeL 90, Flasher17a,Flasher17b,Flasher17,Flasher17off   ' JoinCircus flasher
FadeL 91, Flasher18a,Flasher18b,Flasher18,Flasher18off   ' Ring1 flasher
FadeL 92, Flasher19a,Flasher19b,Flasher19,Flasher19off   ' Ring2 flasher
FadeL 93, Flasher20a,Flasher20b,Flasher20,Flasher20off   ' Ring3 flasher
FadeL 94, Flasher23a,Flasher23b,Flasher23,Flasher23off   ' Boom! Balloon flasher
'FadeL 95, Flasher21a,Flasher21b,Flasher21,Flasher21off   ' Upper Right Backbox flasher
'FadeL 96, Flasher24a,Flasher24b,Flasher24,Flasher24off   ' Upper Left Backbox flasher
'FadeL 97, Flasher26a,Flasher26b,Flasher26,Flasher26off   ' Lower Left Backbox flasher
'FadeL 98, Flasher28a,Flasher28b,Flasher28,Flasher28off   ' Lower Right Backbox flasher
End Sub

'-------------------------------------------------------------------------------------------
'Core Found Below - Call the VBS file as indicated above; otherwise append to end of script
'-------------------------------------------------------------------------------------------
'System defines variables and assigns the changed light values to them, which is then turned over to Fader Control
Dim lightnum(151) : Dim Tset
'Initialize all possible light control variables (0 - 150) including extra spaces for flashers or GI control
On Error Resume Next
	For Tset = 0 To 150
		lightnum(Tset) = 0
	Next

'Assign All Lamp Functions to Variable Control List And Call Fading Lights
' - Variable "Fading" controls whether lights fade or not (can use from options menu or change in script)
'Dim Fading    : Fading = True ' appears earlier on under options

'Note This Sub is for VPM tables and assigns lamp values automatically.  Originals should use the one marked
'     below instead.  Therefore only create the timer you need (either LightControl or LightControlO)
'
Sub LightControl_Timer()
	Dim ChgLamp, pointer, index, str, T
	  ChgLamp = Controller.ChangedLamps
	On Error Resume Next
	If Fading = True Then 
		For T = 0 To UBound(ChgLamp)
			pointer = chgLamp(T, 0)
			index   = chgLamp(T, 1)
			lightnum(pointer) = index + 4
		Next
	Else
		For T = 0 To UBound(ChgLamp)
			pointer = chgLamp(T, 0)
			index   = chgLamp(T, 1)
			lightnum(pointer) = index
		Next
	End If
    UpdateLights
End Sub

'Note: This timer is for original tables.  Light states are assigned using the "SetLight" sub marked below this one.
'      It is also used to assign flasher or GI lights to unused light numbers and thus added to the fade system.

 Sub LightControlO_Timer()
	UpdateLights
 End Sub

' Light Assignment Control
' - This call allows easy assignments of values to the light array, useful for assigning Flashers or GI Lights or when
'   using the system with original tables to assign lamp states into the control array.  Fading or non-fading calls 
'   are then applied as normal in the UpdateLights sub.
' - Also Set "On" = 1 and "Off" = 0 so they can be used as an alias in the call

dim LightOn, LightOff : LightOn = 1 : LightOff = 0

Sub SetLight(lightnumber, value)
	If fading = true then
		lightnum(lightnumber) = abs(value) + 4
	Else
		lightnum(lightnumber) = abs(value)
	End If
End Sub

'------------------------------------------------
'Light Handler Code With Fade Control V5.1 by PD
'------------------------------------------------
'Fades Light Object based Lights When Multiple Lights are controlled by the Same Variable
'NOTE: The last light controlled by that variable must be called with the regular Sub handler 
'Example call: "FadeLm 1, light1a,light1b,light1,light1off"
Sub FadeLm(lightnumIn, stage1, stage2, stage3, off)
	'lightnum is the controlling light number ; stage 1 is dimmest, stage 2 is in-between ; stage 3 is brightest ; off state is brighter off color 
	Select Case lightnum(lightnumIn)
		Case  5 : stage1.state = 0 : stage2.state = 0 : stage3.state = 0 : stage3.state = 1
		Case  4 : stage3.state = 0 : stage2.state = 0 : stage2.state = 1 
		Case  3 : stage2.state = 0 : stage1.state = 0 : stage1.state = 1 
		Case  2 : stage1.state = 0 : off.state = 0 : off.state = 1 
		Case  1 : off.state    = 0 : stage3.state = 1 
		Case  0 : stage3.state = 0 : off.state = 1 
	End Select
End Sub

'Fades Light Object based Lights 
'Example call: "FadeL 1, light1a,light1b,light1,light1off"
Sub FadeL(lightnumIn, stage1, stage2, stage3, off)
	'lightnum is the controlling light number ; stage 1 is dimmest, stage 2 is in-between ; stage 3 is brightest ; off state is brighter off color
	Select Case lightnum(lightnumIn)
		Case  5 : stage1.state = 0 : stage2.state = 0 : stage3.state = 0 : stage3.state = 1 : lightnum(lightnumIn) = 6
		Case  4 : stage3.state = 0 : stage2.state = 0 : stage2.state = 1 : lightnum(lightnumIn) = lightnum(lightnumIn) - 1
		Case  3 : stage2.state = 0 : stage1.state = 0 : stage1.state = 1 : lightnum(lightnumIn) = lightnum(lightnumIn) - 1
		Case  2 : stage1.state = 0 : off.state = 0 : off.state = 1 : lightnum(lightnumIn) = 6
		Case  1 : off.state    = 0 : stage3.state = 1 : lightnum(lightnumIn) = 6
		Case  0 : stage3.state = 0 : off.state = 1 : lightnum(lightnumIn) = 6
	End Select
End Sub

'Fades Wall Based Lights When Multiple Lights are controlled by the Same Variable
'NOTE: The last light controlled by that variable must be called with the regular Sub handler 
'Example call: "FadeWm 1, light1a,light1b,light1"
Sub FadeWm(lightnumIn, stage1, stage2, stage3)
	'lightnum is the controlling light number ; stage 1 is dimmest, stage 2 is in-between ; stage 3 is brightest ; off state is brighter off color
	Select Case lightnum(lightnumIn)
		Case  5 : stage1.IsDropped = True : stage2.IsDropped = True : stage3.IsDropped = False 
		Case  4 : stage3.IsDropped = True : stage2.IsDropped = False 
		Case  3 : stage2.IsDropped = True : stage1.IsDropped = False 
		Case  2 : stage1.IsDropped = True
		Case  1 : stage1.IsDropped = True : stage2.IsDropped = True : stage3.IsDropped = False
		Case  0 : stage1.IsDropped = True : stage2.IsDropped = True : stage3.IsDropped = True
	End Select
End Sub

'Fades Wall Based Lights
'Example call: "FadeW 1, light1a,light1b,light1"
Sub FadeW(lightnumIn, stage1, stage2, stage3)
	'lightnum is the controlling light number ; stage 1 is dimmest, stage 2 is in-between ; stage 3 is brightest ; off state is brighter off color
	Select Case lightnum(lightnumIn)
		Case  5 : stage1.IsDropped = True : stage2.IsDropped = True : stage3.IsDropped = False : lightnum(lightnumIn) = 6
		Case  4 : stage3.IsDropped = True : stage2.IsDropped = False : lightnum(lightnumIn) = lightnum(lightnumIn) - 1
		Case  3 : stage2.IsDropped = True : stage1.IsDropped = False : lightnum(lightnumIn) = lightnum(lightnumIn) - 1
		Case  2 : stage1.IsDropped = True : lightnum(lightnumIn) = 6
		Case  1 : stage1.IsDropped = True : stage2.IsDropped = True : stage3.IsDropped = False : lightnum(lightnumIn) = 6
		Case  0 : stage1.IsDropped = True : stage2.IsDropped = True : stage3.IsDropped = True  : lightnum(lightnumIn) = 6
	End Select
End Sub

'Fades Reel Based Lights When Multiple Lights are controlled by the Same Variable
'NOTE: The last light controlled by that variable must be called with the regular Sub handler 
'Example call: "FadeRm 1, light1"
Sub FadeRm(lightnumIn, reelname)
	'Note that reel construction order must be off, bright, stage1, stage2
	Select Case lightnum(lightnumIn)
		Case  5 : reelname.setvalue 1 
		Case  4 : reelname.setvalue 3  
		Case  3 : reelname.setvalue 2  
		Case  2 : reelname.setvalue 0 
		Case  1 : reelname.setvalue 1
		Case  0 : reelname.setvalue 0
	End Select
End Sub

'Fades Reel Based Lights
'Example call: "FadeR 1, light1"
Sub FadeR(lightnumIn, reelname)
	'Note that reel construction order must be off, bright, stage1, stage2
	Select Case lightnum(lightnumIn)
		Case  5 : reelname.setvalue 1 : lightnum(lightnumIn) = 6
		Case  4 : reelname.setvalue 3 : lightnum(lightnumIn) = lightnum(lightnumIn) - 1
		Case  3 : reelname.setvalue 2 : lightnum(lightnumIn) = lightnum(lightnumIn) - 1
		Case  2 : reelname.setvalue 0 : lightnum(lightnumIn) = 6
		Case  1 : reelname.setvalue 1 : lightnum(lightnumIn) = 6
		Case  0 : reelname.setvalue 0 : lightnum(lightnumIn) = 6
	End Select
End Sub

'Handles regular on/off lights or objects like Pop Bumpers or single lights (e.g.light1)
'Example call: "NFade 1, light1"
Sub NFade(lightnumIn,light)
	Select Case lightnum(lightnumIn)
		Case 5: light.state = 1
		Case 4: light.state = 0
		Case 1: light.state = 1
		Case 0: light.state = 0
	End Select
End Sub

'Handles permanant 2-state lights (uses 2-lamps, one for on and one for off) (e.g. light1 and light1off)
'Example call: "LitL2 1, light1, light1off"
Sub LitL2(lightnumIn, light, lightoff) 
	Select Case lightnum(lightnumIn)
		Case 5: lightoff.state = 0 : light.state    = 1
		Case 4: light.state    = 0 : lightoff.state = 1
		Case 1: lightoff.state = 0 : light.state    = 1
		Case 0: light.state    = 0 : lightoff.state = 1
	End Select
End Sub

'Handles 2-state (on/off only) Wall Based Lights
'Example call: "LitW2 1, light1"
Sub LitW2(lightnumIn, stage3)
	Select Case lightnum(lightnumIn)
		Case 5: stage3.IsDropped = 0
		Case 4: stage3.IsDropped = 1
		Case 1: stage3.IsDropped = 0
		Case 0: stage3.IsDropped = 1
	End Select
End Sub

'********************
'AUTO-LABEL HANDLERS
'********************
'NOTE: These take a big chunk of CPU time to process the labeling in real time, but they allow you to 
' just enter [lightnum,lightOnObject] instead of [lightnum, Lighta, Lightb, LightOn, LightOff]
' Example: aFadeL 11,Light11
'                versus
'           FadeL 11,Light11a,Light11b,Light11,Light11off
'
'These ONLY apply to the Light and Wall Fade handlers.  The Reel handler is the same in both cases and suffers no
'significant CPU use regardless

'Fades Light Object based Lights When Multiple Lights are controlled by the Same Variable
'NOTE: The last light controlled by that variable must be called with the regular Sub handler 
'Example call: "aFadem 1, light1"
Sub aFadeLm(lightnumIn, stage3)
	'lightnum is the controlling light number ; stage 1 is dimmest, stage 2 is in-between ; stage 3 is brightest ; off state is brighter off color 
	dim stage1on : stage1on = "" & stage3.name & "a.state = 1" : dim stage1off : stage1off = "" & stage3.name & "a.state = 0"
	dim stage2on : stage2on = "" & stage3.name & "b.state = 1" : dim stage2off : stage2off = "" & stage3.name & "b.state = 0"
	dim offstaton: offstaton= "" & stage3.name & "off.state=1" : dim offstatoff: offstatoff= "" & stage3.name & "off.state=0"

	Select Case lightnum(lightnumIn)
		Case  5 : ExecuteGlobal stage1off : ExecuteGlobal stage2off : stage3.state = 0 : stage3.state = 1
		Case  4 : stage3.state = 0 : ExecuteGlobal stage2off : ExecuteGlobal stage2on 
		Case  3 : ExecuteGlobal stage2off : ExecuteGlobal stage1off : ExecuteGlobal stage1on 
		Case  2 : ExecuteGlobal stage1off : ExecuteGlobal offstatoff : ExecuteGlobal offstaton 
		Case  1 : ExecuteGlobal offstatoff: stage3.state = 1 
		Case  0 : stage3.state = 0 : ExecuteGlobal offstaton 
	End Select
End Sub

'Fades Light Object based Lights 
'Example call: "aFade 1, light1"
Sub aFadeL(lightnumIn, stage3)
	'lightnum is the controlling light number ; stage 1 is dimmest, stage 2 is in-between ; stage 3 is brightest ; off state is brighter off color
	dim stage1on : stage1on = "" & stage3.name & "a.state = 1" : dim stage1off : stage1off = "" & stage3.name & "a.state = 0"
	dim stage2on : stage2on = "" & stage3.name & "b.state = 1" : dim stage2off : stage2off = "" & stage3.name & "b.state = 0"
	dim offstaton: offstaton= "" & stage3.name & "off.state=1" : dim offstatoff: offstatoff= "" & stage3.name & "off.state=0"

	Select Case lightnum(lightnumIn)
		Case  5 : ExecuteGlobal stage1off : ExecuteGlobal stage2off : stage3.state = 0 : stage3.state = 1 : lightnum(lightnumIn) = 6
		Case  4 : stage3.state = 0 : ExecuteGlobal stage2off : ExecuteGlobal stage2on  : lightnum(lightnumIn) = lightnum(lightnumIn) - 1
		Case  3 : ExecuteGlobal stage2off : ExecuteGlobal stage1off : ExecuteGlobal stage1on : lightnum(lightnumIn) = lightnum(lightnumIn) - 1 
		Case  2 : ExecuteGlobal stage1off : ExecuteGlobal offstatoff : ExecuteGlobal offstaton : lightnum(lightnumIn) = 6
		Case  1 : ExecuteGlobal offstatoff: stage3.state = 1 : lightnum(lightnumIn) = 6
		Case  0 : stage3.state = 0 : ExecuteGlobal offstaton : lightnum(lightnumIn) = 6
	End Select
End Sub

'Fades Wall Based Lights When Multiple Lights are controlled by the Same Variable
'NOTE: The last light controlled by that variable must be called with the regular Sub handler 
'Example call: "aFadeWm 1, light1"
Sub aFadeWm(lightnumIn, stage3)
	'lightnum is the controlling light number ; stage 1 is dimmest, stage 2 is in-between ; stage 3 is brightest ; off state is brighter off color
	dim stage1on : stage1on = "" & stage3.name & "a.IsDropped = 1" : dim stage1off : stage1off = "" & stage3.name & "a.IsDropped = 0"
	dim stage2on : stage2on = "" & stage3.name & "b.IsDropped = 1" : dim stage2off : stage2off = "" & stage3.name & "b.IsDropped = 0"
	Select Case lightnum(lightnumIn)
		Case  5 : ExecuteGlobal stage1on  : ExecuteGlobal stage2on : stage3.IsDropped = False 
		Case  4 : stage3.IsDropped = True : ExecuteGlobal stage2off 
		Case  3 : ExecuteGlobal stage2on  : ExecuteGlobal stage1off 
		Case  2 : ExecuteGlobal stage1on
		Case  1 : ExecuteGlobal stage1on  : ExecuteGlobal stage2on : stage3.IsDropped = False
		Case  0 : ExecuteGlobal stage1on  : ExecuteGlobal stage2on : stage3.IsDropped = True
	End Select
End Sub

'Fades Wall Based Lights
'Example call: "aFadeW 1, light1"
Sub aFadeW(lightnumIn, stage3)
	'lightnum is the controlling light number ; stage 1 is dimmest, stage 2 is in-between ; stage 3 is brightest ; off state is brighter off color
	dim stage1on : stage1on = "" & stage3.name & "a.IsDropped = 1" : dim stage1off : stage1off = "" & stage3.name & "a.IsDropped = 0"
	dim stage2on : stage2on = "" & stage3.name & "b.IsDropped = 1" : dim stage2off : stage2off = "" & stage3.name & "b.IsDropped = 0"
	Select Case lightnum(lightnumIn)
		Case  5 : ExecuteGlobal stage1on  : ExecuteGlobal stage2on : stage3.IsDropped = False : lightnum(lightnumIn) = 6
		Case  4 : stage3.IsDropped = True : ExecuteGlobal stage2off : lightnum(lightnumIn) = lightnum(lightnumIn) - 1
		Case  3 : ExecuteGlobal stage2on  : ExecuteGlobal stage1off : lightnum(lightnumIn) = lightnum(lightnumIn) - 1
		Case  2 : ExecuteGlobal stage1on  : lightnum(lightnumIn) = 6
		Case  1 : ExecuteGlobal stage1on  : ExecuteGlobal stage2on : stage3.IsDropped = False : lightnum(lightnumIn) = 6
		Case  0 : ExecuteGlobal stage1on  : ExecuteGlobal stage2on : stage3.IsDropped = True  : lightnum(lightnumIn) = 6
	End Select
End Sub

'Handles permanant 2-state lights (uses 2-lamps, one for on and one for off) (e.g. light1 and light1off)
'Example call: "aLitL2 1, light1"
Sub aLitL2(lightnumIn, light) 
	dim lightoff_on : lightoff_on = "" & light.name & "off.state = 1" : dim lightoff_off : lightoff_off = "" & light.name & "off.state = 0"
	Select Case lightnum(lightnumIn)
		Case 5: ExecuteGlobal lightoff_off : light.state = 1
		Case 4: light.state    = 0         : ExecuteGlobal lightoff_on
		Case 1: ExecuteGlobal lightoff_off : light.state    = 1
		Case 0: light.state    = 0         : ExecuteGlobal lightoff_on
	End Select
End Sub

'------------------------------------
'Handle Case of disabling All Lights
'------------------------------------
Sub AllLightsOff()
	'Set all Control Variables to 0 and call fade update 3 times to reset all lights to off
	On Error Resume Next
		For Tset = 0 To 150
			lightnum(Tset) = 0
		Next
	UpdateLights : UpdateLights : UpdateLights
End Sub

'=======================================================
'Additions to hide balls behind Ringmaster on the ramps
'=======================================================
Dim MyBall

Sub MyBallShow1a_Hit 
Set MyBall=ActiveBall 
If MyBall.VelX>0 or MyBall.VelY>0 or MyBall.VelZ>0 Then  
MyBall.Image="BallImage9" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  
 
Sub MyBallHide1a_Hit 
Set MyBall=ActiveBall 
If InvisiBallFlag=True Then  
MyBall.Image="InvisiBall" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  

Sub MyBallHide1b_Hit 
Set MyBall=ActiveBall 
If InvisiBallFlag=True Then  
MyBall.Image="InvisiBall" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  

Sub MyBallHide1c_Hit 
Set MyBall=ActiveBall 
If InvisiBallFlag=True Then  
MyBall.Image="InvisiBall" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  

Sub MyBallShow1b_Hit 
Set MyBall=ActiveBall 
If MyBall.VelX>0 or MyBall.VelY>0 or MyBall.VelZ>0 Then   
MyBall.Image="BallImage9" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub 

Sub MyBallShow2a_Hit 
Set MyBall=ActiveBall 
If MyBall.VelX>0 or MyBall.VelY>0 or MyBall.VelZ>0 Then  
MyBall.Image="BallImage9" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  

Sub MyBallHide2a_Hit 
Set MyBall=ActiveBall 
If InvisiBallFlag=True Then  
MyBall.Image="InvisiBall" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  

Sub MyBallHide2b_Hit 
Set MyBall=ActiveBall 
If InvisiBallFlag=True Then  
MyBall.Image="InvisiBall" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  

Sub MyBallHide2c_Hit 
Set MyBall=ActiveBall 
If InvisiBallFlag=True Then  
MyBall.Image="InvisiBall" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  

Sub MyBallShow2b_Hit 
Set MyBall=ActiveBall 
If MyBall.VelX>0 or MyBall.VelY>0 or MyBall.VelZ>0 Then  
MyBall.Image="BallImage9" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  

'---------------------------------------------------
' Additions to hide balls falling behind Ringmaster
'---------------------------------------------------
Sub MyBallHide3a_Hit 
Set MyBall=ActiveBall 
If InvisiBallFlag=True Then  
MyBall.Image="InvisiBall" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  

Sub MyBallShow3a_Hit 
Set MyBall=ActiveBall 
If MyBall.VelX>0 or MyBall.VelY>0 or MyBall.VelZ>0 Then  
MyBall.Image="BallImage9" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub

Sub MyBallHide3b_Hit 
Set MyBall=ActiveBall 
If InvisiBallFlag=True Then  
MyBall.Image="InvisiBall" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  

Sub MyBallShow3b_Hit 
Set MyBall=ActiveBall 
If MyBall.VelX>0 or MyBall.VelY>0 or MyBall.VelZ>0 Then  
MyBall.Image="BallImage9" 
Else 
MyBall.Image="BallImage9" 
End If 
End Sub  
