Multiple Player Routine
The "HowTo" series of Visual Pinball tables is presented mainly for the person who is trying to understand how to implement certain events in Visual Pinball scripting.
So why create a stand-alone "How-To" table when there are many great tutorial tables already available? Because, as a "newbie", it can be very tedious and often confusing to sort thru lines and lines of scripting devoted to many different features of a table trying to find out how a certain feature is done. My thought was why not just present one feature on a table so that the tedium and confusion might be held to a minimum? The tables will look very dull and flat and very uninteresting and playing them will not be as full of flash and pizzazz as a full blown table. But the intent is, first, to present as clearly and simply as possible the underlying scripting and events of a given feature while, secondly, keeping the table's filesize to a minimum for the sake of convenience. And remember that this is not necessarily "how you do it". What I intended to do was to present the concept of a given feature and to show at least one way to implement the controls to create that feature. The code has been heavily, but simply, commented as to what is going on and why certain things are done. Not every nuance of a feature can be addressed in every case. But by gaining a general understanding of a feature's concept, much less frustration will be experienced when building your table. That helps contribute to keeping a table designer happy, and a happy table designer is a productive table designer! BJ The following is the script from BJ's tutorial table on Multiple Players:
Code
' OOPS! The feature of Multiple Players, for this example, uses several
' tools in order to effect the expected results. All actions are commented
' as often and as simply as possible to keep your head from exploding.
' Lets create some variables to keep track of certain things
' The names describe pretty much what we're keeping track of
Dim HowManyPlayers, PlayerNumber
Dim ScoreP1, ScoreP2, ScoreP3, ScoreP4
Dim GameOn
Sub Table1_Init() 'do all this stuff when the table is first loaded
GameOn = 0
Light1.State = LightStateOff
Light2.State=0 ' same as "LightStateOff"
Light3.State=0
Light4.State=0
PlayerNumber = 0
ScoreP1 = 0
ScoreP2 = 0
ScoreP3 = 0
ScoreP4 = 0
'Display some information
ScoreText.Text = "Press ""5"" to Add a Player," & vbcr & _
"Press ""S"" to Start"
End Sub
Sub AddScore(Points) ' see the "HowTo_KeepScore" table for explanation
'In "case" the value of PlayerNumber is a certain value, do a certain
'action
Select case PlayerNumber
case 1
ScoreP1 = ScoreP1 + Points
ScoreText.Text = ScoreP1
case 2
ScoreP2 = ScoreP2 + Points
ScoreText.Text = ScoreP2
case 3
ScoreP3 = ScoreP3 + Points
ScoreText.Text = ScoreP3
case 4
ScoreP4 = ScoreP4 + Points
ScoreText.Text = ScoreP4
Bullet6 end Select
Bullet6 end Sub
Sub Drain_Hit() 'standard "Drain" script modified for this feature
Drain.DestroyBall
'Script modifications:
'Current player's ball has drained,
'Need to determine which player is next
If PlayerNumber < HowManyPlayers then
PlayerNumber = PlayerNumber + 1
Else
PlayerNumber = 1
End If
CheckScores() ' Call the Bullet6 next subroutine
Plunger.CreateBall
PlaySound "Plunger"
Bullet6 end Sub
Sub CheckScores()
'The following uses a feature called a "Collection"
'I have created a colletion of lights called PlayerLights that includes
'Light1 thru Light4 (one light for each player)
'This will allow easier access to all of the light states at once Bullet6 time
'A nifty feature you should learn to use. It's under the "Tables" menu
'selection on the Editor toolbar.
For Each Light in PlayerLights ' Nifty code to access all of the lights
Light.State = LightStatOff
Bullet6 next
'the following is Code to effect certain events under certain
'conditions or "cases"
'In this "case", the value of PlayerNumber is determined and, according
'to the value, light the appropriate light and display the appropriate
'score value
Select Case PlayerNumber
Case 1
Light1.State = 1
ScoreText.Text = ScoreP1
Case 2
Light2.State = 1
ScoreText.Text = ScoreP2
Case 3
Light3.State = 1
ScoreText.Text = ScoreP3
Case 4
Light4.State = 1
ScoreText.Text = ScoreP4
End Select
End Sub
Sub Bumper1_Hit()
AddScore (100)
'call the "AddScore" subroutine and hand it a value to process
End Sub
Sub Table1_KeyDown(ByVal keycode)
if KeyCode = 6 then ' Coin has been inserted
If HowManyPlayers = 0 then
PlayerNumber = 1
HowManyPlayers = 1
Light1.State = 1
ElseIf HowManyPlayers = 1 then
HowManyPlayers = 2
Light2.State = 1
ElseIf HowManyPlayers = 2 then
HowManyPlayers = 3
Light3.State = 1
ElseIf HowManyPlayers = 3 then
HowManyPlayers = 4
Light4.State = 1
ElseIf HowManyPlayers = 4 then
MsgBox "4 Players is the limit",0,"Player Number Exceeded"
End If
End If
If KeyCode = 19 and GameOn = 1 then' "R" Bullet6 key to Review Scores
MsgBox "Player 1 = " & ScoreP1 & vbcr & vbcr & Bullet6 _
"Player 2 = " & ScoreP2 & vbcr & vbcr & Bullet6 _
"Player 3 = " & ScoreP3 & vbcr & vbcr & Bullet6 _
"Player 4 = " & ScoreP4, 0, "REVIEW SCORES"
Bullet6 end if
if KeyCode = 31 then' "Start" key (S) has been pressed
GameOn = 1
If HowManyPlayers > 0 then
CheckScores()
Else
ScoreText.Text = "Insert Coin"
End If
PlaySound "Plunger"
Plunger.CreateBall
End If
If keycode = PlungerKey Then
If GameOn = 1 Then
Plunger.PullBack
End If
End If
If keycode = LeftFlipperKey Then
LeftFlipper.RotateToEnd
PlaySound "FlipperUp"
End If
If keycode = RightFlipperKey Then
RightFlipper.RotateToEnd
PlaySound "FlipperUp"
End If
If keycode = LeftTiltKey Then
Nudge 90, 2
End If
If keycode = RightTiltKey Then
Nudge 270, 2
End If
If keycode = CenterTiltKey Then
Nudge 0, 2
End If
End Sub
Sub Table1_KeyUp(ByVal keycode)
If keycode = PlungerKey Then
Plunger.Fire
End If
If keycode = LeftFlipperKey Then
LeftFlipper.RotateToStart
PlaySound "FlipperDown"
End If
If keycode = RightFlipperKey Then
RightFlipper.RotateToStart
PlaySound "FlipperDown"
End If
End Sub
Sub LeftSlingshot_Slingshot()
PlaySound "Bumper"
End Sub
Sub RightSlingshot_Slingshot()
PlaySound "Bumper"
End Sub
Updated Jun 22, 2005 Written by BJ