Future Pinball's Manual is great for scripters, since it gives detailed info on which functions you have available for your table objects. That being said, it doesn't showcase all the options, and that means there are some things you can do on your tables that probably many scripters don't know about, and in some cases those can be a life changer.
Of course, no wonder some of these things are not included on the guide, since I can't find a single use case for them. For example, did you know sequence effects (Light Sequencer effects, Queue Texts in DMD & Display, etc.) have an extra option to apply the last one used?
I'll be posting on this topic a collection of the (non-BAM) code snippets I find more useful, and probably I'll also include a few more advanced stuff later, this way even the expert coders may find something new to play with.
1. Object properties: Introduction
Let's talk nomenclature just a little, to make sure we're on the same page.
Table objects have basically three types of
callers, and the manual refers to them with these names:
-
Script properties
Example:
Bulb.State = BulbOn
-
Script methods
Example:
Kicker.CreateBall()
-
Script events
Example:
Sub Timer_Expired()
What some people might not know, is Editor properties are also "script properties", so they can be called via script. Most of them are
ReadOnly, which means they can't be modified, but it may still be useful to know you can obtain them.
For example, you can use
Light.X
and
Light.Y
to obtain the coordinates of a Light, which could be useful to implement some kind of light simple pattern. Coordinates could also be used to calculate the distance between two triggers, and with the help of a timer, you could even get an approximation of the speed of the ball through a lane. Of course where we run BAM flies, but this approach could be enough in some cases.
Another example: You can use
DropTarget.BankCount
to check how many Event IDs a DropTarget includes, so with this you could make a function that checks every single one independent of how many targets that specific bank has. As you can see, the script properties usually have the same name as in the Editor, without any space or special character.
The default script has only one example usage of this. The variable
LastSwitchHit defines the last trigger object that was hit. To check which one it was, it uses its name string, therefore using the editor property
Trigger.Name
:
Code:
If (LastSwitchHit.Name = "PlungerLaneTrigger") Then
bBallSaverActive = True
End If
You may not be convinced of its potential yet, but I needed to explain this in order to move on to those properties that
can be modified via script.
2. Advanced Kickers
One of the most important properties you can modify via script is Rotation. Sadly, that's not particularly usable in those objects with a collision box, since it doesn't change its rotation. Hope's not entirely lost though, because some object types can use models with "Per polygon collision" instead. Kickers use that option.
You can modify many Kicker properties in real time.
-
Rotation
You can easily make a "Two directional kicker" that launches the ball up or down depending on where it came from (you would check this with two invisible triggers). If the kicker model is symmetrical, the rotation won't be visible, only its effect.
Code:
Dim LastTriggerPressed ' 0: Up, 1: Down
' Update the variable LastTriggerPressed
Sub UpTrigger_Hit()
LastTriggerPressed = 0
End Sub
Sub DownTrigger_Hit()
LastTriggerPressed = 1
End Sub
' The Kicker is Hit
Sub DoubleKicker_Hit()
If (LastTriggerPressed = 0) Then
' Look up
DoubleKicker.Rotation = 0
Else
' Look down
DoubleKicker.Rotation = 180
End If
' Launch the ball to the current position
DoubleKicker.SolenoidPulse()
End Sub
You could also make a PinBelt that launches the ball to a random direction, like a very basic magnet release. You will need a MakeRandom function for that:
Code:
' Function to get a random number between two numbers (both included)
Function MakeRandom(ByVal min, ByVal max)
MakeRandom = CInt(Int((max - min + 1) * Rnd())) + min
End Function
Code:
Sub PinBelt_Hit()
PinBelt.Rotation = MakeRandom(0, 359)
PinBelt.SolenoidPulse()
End Sub
-
Kicker Type
You can set your Kicker's type (Directional or VerticalUpKicker) via script.
Code:
Kicker.KickerType = 0 ' Directional
Kicker.KickerType = 2 ' Vertical
On this example, a vertical kicker launches the ball to a wire ramp, but on TILT it simply releases it back to the playfield. In order to release it properly, you will have to define its angle on the Editor, even if the model Kicker-Hole-T3 doesn't look rotational. I would recommend making a custom model that makes it clear the kicker is "double".
Code:
Sub VerticalKicker_Hit()
If (fpTilted = True) Then
' On Tilt mode, release the ball back to the playfield
VerticalKicker.KickerType = 0
VerticalKicker.Strength = 1
VerticalKicker.SolenoidPulse()
Else
' By default, launch the ball to the wire
VerticalKicker.KickerType = 2
VerticalKicker.Strength = 7
VerticalKicker.SolenoidPulse()
End If
End Sub
-
Strength
You can set the Kicker's strength via script, from 1 to 9. With this, you could make a Kicker that launches the ball harder the longer you've pressed the Plunger key, for example. Usually you will use this for more basic cases, for example on the previous examples you may want to change the strength when you change directions as well.
-
Ball Weight
When you create a ball, you can define its "weight". Without BAM this is a cheap trick, but it kind of works…
The idea behind this has nothing to do with the kicker, nor the ball; what you have to change is the table slope. That change doesn't apply on current balls, but it does apply on new ones. This way, to make a very "light" ball first you would set the Table Slope to 1, create the ball with a Kicker, and set the Table Slope back to its default value again. Note the Table has a Name property as well, just like any other object in the Editor, that's why this is possible.
Code:
' Create a "plastic" ball
Sub CreatePlasticBall()
' Store the default table slope
Dim DefaultSlope : DefaultSlope = NewTable.TableSlope
' Set the slope to 3 to create a light ball
NewTable.TableSlope = 3
' (You may want to make the ball a different colour)
CaptiveKicker.CreateBall
' Set the slope to the default value again
NewTable.TableSlope = DefaultSlope
End Sub
Since this is a bit weird, I would only recommend using it for captive balls, to control their resilience to the player ball. For more complex cases, you could theoretically assign a special
BallID to "plastic" balls and modify other object's strength (or effect) based on that, when the ball hits them. Remember, you can set a custom color to the ball as well, to make that more clear… I haven't even tried any of that, though
Well, I talk way too much. This is all for now, but there's still more to come!
I hope you find this useful!