Subtract Lives

Pinball

Noob
Joined
Jul 25, 2010
Messages
6
Reaction score
0
Points
2
Favorite Pinball Machine
Visual Pinball
Hello,
my tables is almost finished but I would like make a lives box.
I've maked it but how must I write the script?
I've tried with:
Dim Lives
.
.
.
Sub Drain_Hit()
Drain.DestroyBall
Plunger.CreateBall
PlaySound "Plunger"
AddLives (-1)
End Sub

Sub AddLives(Points)
Lives=Lives+Points
LivesText1.Text=Lives
End Sub
When I start the table the lives box shows 3
but when my ball is going to the "Drain" my lives box shows -1
:headscratch:
 
Last edited:
I need to apologize. The variable Points is an internal variable provided in the Visual Pinball.exe, so that should only be used for calculating the Score, but it does work for any numerical value. Typically we use a counter statement like
Lives = Lives - 1
at any appropriate place in an appropriate Sub, for instance, at the Drain.
This is the simple version. Press the 1 key to start the game:

Dim Lives, Game

Sub Table1_KeyDown(ByVal keycode)

If keycode = 2 And Game = False Then
Table1_Init()
End If
End Sub

Sub Table1_Init()
If Game = False Then
Game = True
Lives = 3
LivesText1.Text = Lives
Plunger.CreateBall
PlaySound "Plunger"
End If
End Sub

Sub Drain_Hit()
If Lives = 0 Then
Game = False
TextBox2.Text = "Game Over"
Exit Sub
Else
Lives = Lives - 1
LivesText1.Text = Lives
Plunger.CreateBall
PlaySound "Plunger"
End If
End Sub


Note that if you use your version of the script code, that you do not have to use the name AddLives() or the command Add. The command Add is used in a statement which is a line inside of a Sub or Function. You can name the Sub any original unique name like Spaghetti() and it will still work. You can create a new variable, say Dim Meatballs and use it in

Sub Drain_Hit()
Spaghetti(-1)
End Sub

Sub Spaghetti(Meatballs)
Spaghetti = Spaghetti + Meatballs
TextBox1.Text = Spaghetti
End Sub


...and the value (-1) will be passed to the variable Meatballs the same, but without using the internal Points variable to do so.

Do you have the lines Lives = 3 followed by LivesText1.Text = Lives in the script?

EDIT: Also note that a counter statement can be used to add, subtract, multiply, divide, or any mathematical operation on any numbers you like.
Lives = Lives + 1
Lives = Lives - 4
Lives = Lives * .50
Lives = Lives / 10000

...and they all will work, but with different numerical results of course.
 
Last edited:
And something else.
In the Script Editor, note the Pull-Downs at the top of the Editor.
To automatically make a Sub Table1_Init() , Click the Pull-Down on the left. Find and select Table1
Then click the Pull-Down on the right side and select Init.
Look at the bottom of the script. You should now have a new, empty
Sub Table1_Init()

End Sub


...to put code lines in.
 
Umm....there is now an another problem:
The ball falls through the plunger and I cant pull it back
What is it?
 
Is this on a standard out-of-the-box Plunger or is this a custom plunger lane that you made?

It could be that the Plunger is set to a surface other than the playfield (height) in the Plunger Options > Position menu. Click on the Plunger and make sure the Plunger (mounting) Surface is set to None or if you are using a custom Wall in the Plunger lane, then try setting the Plunger > Surface Pull-Down to it.
 
Press the 1 key to start the game:
What do you mean with Press the 1 key to start the game?
I've tried it...
It doesnt work.
But the problem with the plunger is solved.
I must give it a new name.
but now I cant pull it back
:headscratch:
 
In the sample code above, if you insert this If/Then statement in the keydown Sub that is already generated in the script:
Sub Table1_KeyDown(ByVal keycode)

If keycode = 2 And Game = False Then
Table1_Init()
End If

End Sub

and then in play press the top 1 key (don't use the NUMPAD 1 key)
the keypress will tell the program to go to the Sub Table1_Init() and start a new game EDIT: Only when there is no game in progress...,
but I should say that it is better to use a different name for a Sub that starts a game, something like Sub gamestart() so that the Table1_Init() can still be used to set up basic events separately from the act of starting a game. Also, if you try this sample code, you will want to delete the
Sub Plunger_Init() from the script so that you do not create two balls on the first game, only the ball created when you go to the Sub Table1_Init() ---> Sub gamestart()

Footnote: The top 1 key is identified in the system as keycode = 2 due to the vagaries of the Visual Basic Scripting language. You can find the keycodes for all keys by opening a new table and in script add this line inside of the Sub Table1_KeyDown(ByVal keycode)

ScoreText.Text = keycode

Press any key and its corresponding keycode will appear in the ScoreText (the TextBox) window, including any available keypresses from game control pads, but only when available. The window will only update on available keys pressed.
------------------------------------


If changing the Plunger's name fixes the problem then you probably need to set the Options > Plunger > Position > Surface pull-down to NONE.
I'm guessing that if you open the script and change the name of Sub Plunger_Init() to the new name for the Plunger, then the problem returns, and this is likely because the new name without script changes disassociates the new name Plunger from the commands and sets the new name Plunger Surface to the Default NONE.

But try renaming the Plunger to Plunger and set the Surface setting and let me know what happens because rarely it might be a system error, DirectX or video card bug.
 
Last edited:
Hey, My Bad! I just fell out of bed!
If you change the Plunger name in the Options > Plunger menu then the parameters should behave the same as before, but be aware that any references to the Object, Plunger, etc. by its old name in the script, Subs, etc. will cause the game to crash because the program/script is looking for an Object by Name that "no longer exists".

Do you have "Cache rendered tables" checked? In Visual Pinball9xxx this checkbox will be found on the Options > Table > Colors and Formatting menu and will appear as "Table Render Caching". In Visual Pinball 8xxx it is found at the top of the Editor screen > Preferences > Video Options > "Cache rendered table" and what this does is to save a file of the rendered table to the hard drive and run this file for the table at play, so if checked then even though you are building a new table, the player will be running the older saved (cached) version.

You want to Uncheck this cached box.

As for setting the Plunger surface, as an experiment open a New Table and set the Plunger Surface setting to "Outer Wall". Then start this New Table. The ball should kick out into the plunger lane and roll under the Plunger. Then try resetting the Surface to NONE.
Is this what is happening with the project Table?
 
Last edited:
umm....
I think the problem was in my script:
Sub Red1_KeyDown(ByVal keycode)
If keycode = 2 And Game = False Then
Table1_Init()
End If
End Sub
Sub Red1_Init()
If Game = False Then
Game = True
Lives = 3
LivesText1.Text = Lives
Plunger1.CreateBall
PlaySound "Plunger"
End If
End Sub

Sub Drain_Hit()
If Lives = 0 Then
Game = False
TextBox2.Text = "Game Over"
Exit Sub
Else
Lives = Lives - 1
LivesText1.Text = Lives
Drain.DestroyBall
Plunger1.CreateBall
PlaySound "Plunger"
End If
End Sub
Its easy-peasy:
In the script already exist
Sub Red1_KeyDown(ByVal keycode)
I must duplicate it:
Sub Red1_KeyDown(ByVal keycode)
If keycode = 2 And Game = False Then
Table1_Init()
End If
End Sub
Sub Red1_Init()
If Game = False Then
Game = True
Lives = 3
LivesText1.Text = Lives
Plunger1.CreateBall
PlaySound "Plunger"
End If
End Sub

Sub Drain_Hit()
If Lives = 0 Then
Game = False
TextBox2.Text = "Game Over"
Exit Sub
Else
Lives = Lives - 1
LivesText1.Text = Lives
Drain.DestroyBall
Plunger1.CreateBall
PlaySound "Plunger"
End If
End Sub
Sub Red1_KeyDown(ByVal keycode)
If keycode = PlungerKey Then
Plunger1.PullBack
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 Red1_KeyUp(ByVal keycode)

If keycode = PlungerKey Then
Plunger1.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
Now I can pull-back the plunger.
Thank you!:joy:
 
You should insert all of the If/Then statements for the keypresses/keycodes in the same Sub instead of creating more than one Sub for the same events.
Copy/Paste this in the Sub Red1_KeyDown(ByVal keycode) that has the Plunger.Pullback lines, etc. and delete the extra Sub/lines/End Sub. Note the edit changing from Table1_Init() to Red1()

If keycode = 2 And Game = False Then
Red1()
End If

And then edit/change the name of the Sub Sub Red1_Init() to Red1(). The use of Init is unnecessary here. The term Init is used to initialize the setup of the Table to a playable game on the screen, as in on initial creation and rendering of the Table/the game/the construction of same, and once initialized does not need to be re-initialized, only reset, as in resetting the values contained in the Dims (the Memory Variables), usually in the gamestart(), the Sub Red1() with reset lines like Lives = 3 or Game = True.

You also do not need to create a Sub xxx_Init() because Visual Pinball does this in the background by default (automatically) when clicking the Player mode.
Sub TableX_Init()
routines are used when custom behaviors are desired as the initial Table is created/rendered in the Player screen/mode. This is also true for Object_Init() like Sub Bumper1_Init(), etc.

Now when you open the Table in the Player and press the top 1 key, the game should start and also start a new game after a previous game is ended without exiting the Player screen back to the Editor.
 
Last edited:
Also, you shouldn't need to change the (ByVal keycode) Subs to the custom name of the Table since the Player will accept the name Table1 or the custom name equally.
This is allowable because there is (usually) only one Table in play at any given time.

Now the reason that you need to abide by any name changes of Plungers, etc. is because there might be more than one Plunger used in the design, and because the correct Name identifies to the program which Object, which Plunger to process during an event, for instance, a

If keycode = PlungerKey Then
Plunger.PullBack
End If

or a

If keycode = 30 Then
TheAdditionalSecondRedPlungerNumber4.PullBack
End If
 
Last edited:
General chit-chat
Help Users
You can interact with the ChatGPT Bot in any Chat Room and there is a dedicated room. The command is /ai followed by a space and then your ? or inquiry.
ie: /ai What is a EM Pinball Machine?
  • No one is chatting at the moment.
  • Chat Bot Mibs Chat Bot Mibs:
    maxangelo19 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Dragonslapper has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    royaljet has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Tyfox has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Goldtopboy has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    slick267 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    dabreeze has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Spike has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Tofa has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Atropine has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    bongo2k5 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Bouly has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Felipefx3 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    djrbx has left the room.
  • F @ freebird1963:
    were do music and sound files go
    Quote
  • Chat Bot Mibs Chat Bot Mibs:
    jhbradley has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Conejazo has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Sedulous has left the room.
      Chat Bot Mibs Chat Bot Mibs: Sedulous has left the room.
      Back
      Top