Code/Example Help BAM Timers and variables

Coding and examples for future Pinball and BAM

HZR

Pinball Hall of Famer
Joined
Aug 17, 2021
Messages
498
Solutions
1
Reaction score
148
Points
56
Favorite Pinball Machine
elm street
Can someone help me correct this?


Sub Trigger1_HIT
TimerInterval = 0.1 ' Set timer interval
IncreaseAmount = 0.05 ' Set increase amount for variable
StartTimer "OnTimerTickIncrease", TimerInterval
StopTimer "OnTimerTickDecrease"
End Sub

Sub Trigger2_HIT
TimerInterval = 0.1 ' Set timer interval
IncreaseAmount = 0.05 ' Set decrease amount for variable
StartTimer "OnTimerTickDecrease", TimerInterval
StopTimer "OnTimerTickIncrease"


and can XBAM commands use changing variables? or strings
 
edit....my bad....
i thought you changed a code.
 
Last edited:
I can't say I have ever seen any BAM coding like what you say. The other more experienced coders might have some better ideas than me. But it seems you would need to have two different sets of criteria. Then you would have two sets of if/then statements where each would have one set of criteria that start different timers.

The simpler answer is timers can only have one variable but you can have multiple timers that might be able to do what you want in the right configuration.
 
I can't say I have ever seen any BAM coding like what you say. The other more experienced coders might have some better ideas than me. But it seems you would need to have two different sets of criteria. Then you would have two sets of if/then statements where each would have one set of criteria that start different timers.

The simpler answer is timers can only have one variable but you can have multiple timers that might be able to do what you want in the right configuration.
not the actual code, just example of what im looking to do..

dim timerinterval
dim increaseAmount
timerinterval= .1
increaseAmount = .05

sub timer1_hit()
Start Timer1 "OnTimerTickIncrease", TimerInterval
Stop Timer1 "OnTimerTickDecrease"
End Sub

i want a timer to give me a increasing variable from .1 to 1.0 increasing by .05
but doesnt FP default by miliseconds and starts at 10
i wanted to use the timer value (as it increase) for a bam command
\
thats a visual basic example just trying to rewrite it with future pinball limitations
 
not the actual code, just example of what im looking to do..

dim timerinterval
dim increaseAmount
timerinterval= .1
increaseAmount = .05

sub timer1_hit()
Start Timer1 "OnTimerTickIncrease", TimerInterval
Stop Timer1 "OnTimerTickDecrease"
End Sub

i want a timer to give me a increasing variable from .1 to 1.0 increasing by .05
but doesnt FP default by miliseconds and starts at 10
i wanted to use the timer value (as it increase) for a bam command
\
thats a visual basic example just trying to rewrite it with future pinball limitations
OK, you want a timer to give you an increasing variable from .1 to 1.0 increasing by .05. But what is the time interval for this increase?
Assuming you have a OnTimerTickIncrease with a value of 100 (ms) (and the same value for OnTimerTickDecrease) and a variable named A:

Sub timer1_hit()
OnTimerTickIncrease.Enabled = True
OnTimerTickDecrease.Enabled = False
End Sub

Sub OnTimerTickIncrease_Expired
A = A +increaseAmount
If A > 1 Then A = 1: OnTimerTickIncrease.Enabled = False
End Sub

Sub OnTimerTickDecrease_Expired
A = A -increaseAmount
If A < 0.1 Then A = 0.1: OnTimerTickDecrease.Enabled = False
End Sub
 
Code:
Dim HZR_Timer_Interval : HZR_Timer_Interval = 10
Dim HZR_Timer_Increase: HZR_Timer_Increase = 5
Dim HZR_Timer_Max : HZR_Timer_Max = 1000

Sub HZR_Timer_Expired
    HZR_Timer_Interval = HZR_Timer_Interval + HZR_Timer_Increase
    if HZR_Timer_Interval >= HZR_Timer_Max then HZR_Timer.enabled = false
    HZR_Timer.set True, HZR_Timer_Interval
End Sub

HZR_Timer.set True, HZR_Timer_Interval  'start timer

This will start a timer and use the values set on the DIm lines. It increases it's interval by 5 ms each time. The smallest you can start with is 10ms, but you can increase by however little you want. It will continue to increase each time the timer repeats and then stop it when it reaches the max value.

You can change that up to however you need. You can change the HZR_Timer_Increase value at anytime with different table events, etc.

Popotte was too fast :)
 
Last edited:
Hmm its not going to work, I need decimal values and a timer can only do 10ms, I thought that was the case.

so maybe trigger to trugger to trigger.
increase from trigger a to trigger b then decrese from trigger B to trigger C

Ill think of something

thanks guys. I wasnt sure the OnTimerTIck was supported., I didnt see it in the extracted dll. or Bam that I remember
 
But why do you want a decimal timer (less than 1 ms)? Why do you want one thing happens more than 1 000 times in a second?
 
Hmm its not going to work, I need decimal values and a timer can only do 10ms, I thought that was the case.

so maybe trigger to trugger to trigger.
increase from trigger a to trigger b then decrese from trigger B to trigger C

Ill think of something

thanks guys. I wasnt sure the OnTimerTIck was supported., I didnt see it in the extracted dll. or Bam that I remember

You can use the NewtonPhysicsTick which is the FP physics engine internal timer that is always running non stop. This updates many more times / second (more than 512 / second for sure, as we use that for FizX), but you need to calculate the math to control what you want. If you don't do that, you could have way more cpu cycles / commands being used than you would ever need, and it would make a table run poor, etc.

This is an example that updates FizX flipper stroke, and also updates a Beacon Spotlight flasher to make it rotate, like I use on many tables. Don't ask about how to calculate the Dim i math... that was ravarcade's example. Math can kiss my ass :)

Sub NewtonPhysicsTick()
FlipperStroke() 'FizX
' *** Beacon ***
Dim i
i = ((xBAM.NewtonCounter Mod 384) / 384)
Call BeaconExt.SpotLight(1, i * 360, 90, 50)
End Sub


The reality is... you don't want / need anything to update more than how many times your game will update the display. So for a 60Hz resolution, that 60 times / second... for 120Hz, 120 times / second. Anything more than that is a waste of CPU usage.

You can also use DrawFrameTick timer (which is always running) which will automatically repeat each time the display is updated (as I noted above). I've used this on multiple tables to do different things as well that I wanted to always be updating in realtime automatically.

Sub DrawFrameTick()
Do_Your_stuff
End Sub
 
You can use the NewtonPhysicsTick which is the FP physics engine internal timer that is always running non stop. This updates many more times / second (more than 512 / second for sure, as we use that for FizX),

You sure?

FPS defines the speed at which the engine runs, thus it limiting the "tick". And BTW it is capped internally so you can't really set to whatever you want. I have a post about this in which I quote the full Rav answer to my questions many moons ago.

In short engine clamp fps value to range 20 < fpx < 600. So, if you say "720" it is still 600.

And btw, rav pointed me here at the time.
 
You sure?

FPS defines the speed at which the engine runs, thus it limiting the "tick". And BTW it is capped internally so you can't really set to whatever you want. I have a post about this in which I quote the full Rav answer to my questions many moons ago.



And btw, rav pointed me here at the time.

To clarify... the "physics engine" (Newton) "can" update more than 512 / second... we just set it to 512 for FizX purposes.
 
way beyond what im trying to do, i can set a integer and use triggers which i think is actually better.
how do I throw a integer at a xbam setting
like xbam.trails.color = 255,255,255
ii tried doing R,G,B and defining each as a number
xbam.trails.color = (r,g,b)
also tried xbam.trails,color = Arbg(#,#,#)


IM STILL ABSORBING SCRIPT.... I think Ive caught on pretty well in a year of part time.

anyways

z = ((xBAM.NewtonCounter Mod 384) / 384)
'(Diameter of SpotLight), 384 x degrees of rotation, angle, brightness
' Call FlasherleftRampExt.SpotLight (5, z * 360, 60, 25)

I used a flasher and played with it, Terry, yours look way better..

as always thanks guys.
 
Sence you guys were wondering.
REMEMBER IM A SOAKING WET NEWBIE WITH SCRIPTING


Dim TimerInterval ' The interval at which the timer will fire, in seconds
Dim IncreaseAmount ' The amount by which to increase or decrease the trail length each time the timer fires
Dim DefaultTrailLength '

' Set the default trail length
DefaultTrailLength = 0.48

Function CreateCustomBall ( Source, BallName, Radius, Mass, Opacity )
xBAM.BallRadius = Radius
xBAM.BallMass = 8000 'DEFAULT 8000
xBAM.BallOpacity = Opacity
Dim bi
Set bi = xBAM.BallManager.CreateCustomBall(BallName)
Source.CreateBall bi.Red, bi.Green, bi.Blue, bi.BallNumber
AddDebugText "["&xBAM.BallID&"]"
Dim ball
Set ball = xBAM.BallCloseTo(Source.X, Source.Y)
Set CreateCustomBall = ball
End Function

Sub OnTimerTickIncrease()
' This subroutine is called when the timer fires
' Increase the trail length
If xBAM.Trails.Length < 10 Then ' Set a maximum trail length to prevent it from increasing indefinitely
xBAM.Trails.Length = xBAM.Trails.Length + IncreaseAmount
End If
End Sub

Sub OnTimerTickDecrease()
' This subroutine is called when the timer fires
' Decrease the trail length
If xBAM.Trails.Length > DefaultTrailLength Then
xBAM.Trails.Length = xBAM.Trails.Length - IncreaseAmount
Else
StopTimer "OnTimerTickDecrease" ' Stop the timer when the trail length reaches default length
End If
End Sub

Sub BallTrans(color As String)
Dim ballID () 'define integer
Dim ballType 'define String
Dim ballCreationInfo
Dim transformation

' Get the ID of the DefaultBall
ballID = xBAM.BallManager.GetBallID("DefaultBall")

' Define a custom ball with the specified color
Select Case color
Case "Blue"
ballType = xBAM.BallManager.DefineCustomBall(0, 0, 255, "", "", "")
xBAM.Trails.Color 0, 0, 255
Case "Red"
ballType = xBAM.BallManager.DefineCustomBall(255, 0, 0, "", "", "")
xBAM.Trails.Color 255, 0, 0
Case "Green"
ballType = xBAM.BallManager.DefineCustomBall(0, 255, 0, "", "", "")
xBAM.Trails.Color 0, 255, 0
Case Else
' If no match is found, use default color (white)
ballType = xBAM.BallManager.DefineCustomBall(255, 255, 255, "", "", "")
xBAM.Trails.Color 192, 192, 192 'if nothing matched use this rgb for default color
End Select

' Create the custom ball
ballCreationInfo = xBAM.BallManager.CreateCustomBall(ballType)

' Create a transformation to move the custom ball to the original ball's position
transformation = xBAM.CreateTransformation()
transformation.SetPosition(ballCreationInfo.Position)

' Update the DefaultBall with the custom ball's type and position
xBAM.BallManager.UpdateBall ballID, ballType

End Sub

Sub OnFireballHitTrigger1()
' This subroutine is called when the FIREball hits trigger1
' Start increasing trail length and stop decreasing it if it was decreasing before
TimerInterval = 0.1 ' Set timer interval
IncreaseAmount = 0.05 ' Set increase amount for trail length
StartTimer "OnTimerTickIncrease", TimerInterval
StopTimer "OnTimerTickDecrease"

End Sub

Sub OnFireballHitTrigger2()
' This subroutine is called when the FIREball hits trigger2
' Start decreasing trail length and stop increasing it if it was increasing before
TimerInterval = 0.1 ' Set timer interval
IncreaseAmount = 0.05 ' Set decrease amount for trail length
StartTimer "OnTimerTickDecrease", TimerInterval
StopTimer "OnTimerTickIncrease"

End Sub

' Initialize trail length for DefaultBall at start of game or when new ball is created
xBAM.Trails.Length = DefaultTrailLength

' **** Initialize the pup plug-in ****

Dim PuP_Plug_Tex

Set PuP_Plug_Tex = xBAM.Get("PuPPlugin")
If PuP_Plug_Tex Is Nothing Then
AddDebugText "PuP Plugin is missing"
Else
AddDebugText "PuP Plugin has started"
End if

custom balls and trails all in one with transformations
i have not tweaked it as Im not sure how or if it can be
 
You can use the NewtonPhysicsTick which is the FP physics engine internal timer that is always running non stop. This updates many more times / second (more than 512 / second for sure, as we use that for FizX), but you need to calculate the math to control what you want. If you don't do that, you could have way more cpu cycles / commands being used than you would ever need, and it would make a table run poor, etc.
Yes, but NewtonPhysicsTick depends how powerfull is your machine, isn'it?
And HZR want a 0.1 timer, so 10 000 FPS!
 
Yes, but NewtonPhysicsTick depends how powerfull is your machine, isn'it?
And HZR want a 0.1 timer, so 10 000 FPS!

NewtonPhysicsTick is always running for everyone using FP.

That's why I said, he needs to manage how often anything is updated in that sub (using math to regulate it), because whatever commands that are run in there are going to be updated very often (512 times per second on FizX tables).

FizX updates flippers in that sub. I use it to update rotating beacons (their rotation and size settings) and other things in realtime. As long as they are managed well, there shouldn't be a problem.
 
This is a bit silly, but you could do 1 ms counts by defining 10 enabled timers at 10, 11, ..., 19 ms, and on their Expired calls changing their interval to 10 and calling the same subroutine for each.

Here's an example comparing a normal Timer and a MicroTimer defined this way. With this, you could add as many MicroTimers as you want in your code without needing to add any other object, although having many enabled at the same time may cause lag.

Code:
'----------------------------------------------------------------------------
' ** MicroTimer Class
' Works the same as Timer, but with a lower interval
'----------------------------------------------------------------------------

Class MicroTimer
    Public Name, FrameCount, Interval
    Private bEnabled

    Private Sub Class_Initialize()
        Interval = 1
    End Sub

    Property Get Enabled
        Enabled = bEnabled
    End Property

    Property Let Enabled(ByVal Value)
        If (bEnabled = False) And (Value = True) Then
            FrameCount = 0
        End If
        bEnabled = Value
    End Property

    Public Function Update()
        If (bEnabled = False) Then Exit Function
        FrameCount = FrameCount + 1
        If (FrameCount >= Interval) Then
            CallExpiredEvent()
        End If
    End Function

    Private Sub CallExpiredEvent()
        On Error Resume Next
        Execute Name & "_Expired()"
    End Sub
End Class

'----------------------------------------------------------------------------

' Define a Micro Timer (Demo)
Dim DemoMicroTimer : Set DemoMicroTimer = New MicroTimer
DemoMicroTimer.Name = "DemoMicroTimer"
DemoMicroTimer.Interval = 1

' The 10 timers
Sub T0_Expired() : T0.Interval = 10 : TimerCounterTick() : End Sub
Sub T1_Expired() : T1.Interval = 10 : TimerCounterTick() : End Sub
Sub T2_Expired() : T2.Interval = 10 : TimerCounterTick() : End Sub
Sub T3_Expired() : T3.Interval = 10 : TimerCounterTick() : End Sub
Sub T4_Expired() : T4.Interval = 10 : TimerCounterTick() : End Sub
Sub T5_Expired() : T5.Interval = 10 : TimerCounterTick() : End Sub
Sub T6_Expired() : T6.Interval = 10 : TimerCounterTick() : End Sub
Sub T7_Expired() : T7.Interval = 10 : TimerCounterTick() : End Sub
Sub T8_Expired() : T8.Interval = 10 : TimerCounterTick() : End Sub
Sub T9_Expired() : T9.Interval = 10 : TimerCounterTick() : End Sub

Sub TimerCounterTick()
    ' Update the defined MicroTimers
    DemoMicroTimer.Update()
End Sub

'----------------------------------------------------------------------------

' Demo counters
' DemoTimer is a default Timer with a 10 ms Interval
' DemoMicroTimer is a new MicroTimer with a 1 ms Interval
' DemoMicroCounter should be 10 times higher than DemoCounter

Dim DemoMicroCounter, DemoCounter

' Call on Left Flipper key pressed
Sub DemoMicroStartCount
    DemoMicroCounter = 0
    DemoCounter = 0
    DemoMicroTimer.Enabled = True
    DemoTimer.Enabled = True
End Sub

' Call on Left Flipper key released
Sub DemoMicroEndCount
    DemoMicroTimer.Enabled = False
    DemoTimer.Enabled = False
    AddDebugText "Timer: " + CStr(DemoCounter)
    AddDebugText "MicroTimer: " + CStr(DemoMicroCounter)
End Sub

Sub DemoTimer_Expired()
    DemoCounter = DemoCounter + 1
End Sub

Sub DemoMicroTimer_Expired()
    DemoMicroCounter = DemoMicroCounter + 1
End Sub

My question is why would you need something so precise anyway. I've never needed to go below 10 ms even for moving Toys smoothly around, and things like that. If you need to check something "as fast as possible" and therefore how many milliseconds has each tick is not that relevant, you can use NewtonPhysicsTick instead, as Terry suggested. (The MicroTimer class I provided would still work if you replace TimerCounterTick to NewtonPhysicsTick and remove the unnecessary stuff from my example).
 
...
My question is why would you need something so precise anyway. I've never needed to go below 10 ms even for moving Toys smoothly around, and things like that. If you need to check something "as fast as possible" and therefore how many milliseconds has each tick is not that relevant, you can use NewtonPhysicsTick instead, as Terry suggested. (The MicroTimer class I provided would still work if you replace TimerCounterTick to NewtonPhysicsTick and remove the unnecessary stuff from my example).
I fully agree with you. With a 10 ms timer you just have 100 fps, so something very smooth.
It's just pinball, not a Counter Strike competition...
Normal screen have a 60 Hz refreshment (16 ms timer). Better have 90 Hz refreshment (11 ms timer). After, you have 140 refreshment (7,2 ms timer), and after screen for competition (or for rich men for nothing).
OK you have a lag (for more than 90 Hz), but with an about normal screen, 10 ms is enough.
 
Pinball was the reason I've upgraded to a 240Hz monitor. It's such a fast paced game that ideally I'd have a 1000Hz monitor but thos€ ar€ not availabl€ just y€t... :) Now if only FP engine ran at 1000Hz... Not that it makes a difference. The ball would weight a ton :D

The difference in reaction times to push those buttons is night and day. That's why I don't have a 4k monitor for pinball; even at 120Hz it's still half of what I can do on my 1080p monitor. But I digress.

I do agree that when it comes down to FP, going below 10ms is nonsense and can't actually be defined on a timer. The GUI even puts it at 10 if you try to go lower doesn't it? I'm off for so long I don't even remember this!
 
I was trying to use 2 timers to adjust the length of a ball trail.

the lengths are .01 to 1.0 or .99 that's why i needed decimals not millsieconds.
I could use a trigger and use a integer. I took a break and lost track of why I was using a timer.
I think it had to do with ball transformation and rapidly swapping textures.
 
I was trying to use 2 timers to adjust the length of a ball trail.

the lengths are .01 to 1.0 or .99 that's why i needed decimals not millsieconds.
I could use a trigger and use a integer. I took a break and lost track of why I was using a timer.
I think it had to do with ball transformation and rapidly swapping textures.

Does the "Level" parameter in the ball trails BAM menu not work the way you want?
 
I was trying to use 2 timers to adjust the length of a ball trail.

the lengths are .01 to 1.0 or .99 that's why i needed decimals not millsieconds.
I could use a trigger and use a integer. I took a break and lost track of why I was using a timer.
I think it had to do with ball transformation and rapidly swapping textures.

The ball trails will show based on your ball speed. So if your ball moves slow... then the trails are barely visible. If it moves fast, then you see them leave a longer more visible trail.

What reason are you trying to adjust the trail length value? How were you hoping to adjust it in realtime, or just when certain things happen?

You can just use any table event to change the trail value.
 
Seems I've misunderstood the point of the topic. Anyway, not sure how many use trail effect (not me for sure) but it seems to much work for barely no return if at all, bar coding knowledge or something similar.
 
The ball trails will show based on your ball speed. So if your ball moves slow... then the trails are barely visible. If it moves fast, then you see them leave a longer more visible trail

What reason are you trying to adjust the trail length value? How were you hoping to adjust it in realtime, or just when certain things happen?

You can just use any table event to change the trail value.
True,vhowever .2 vs .45 make them more visable stronger.
Its not that important, its the coding im looking for.

Im trying things I havent seen in any table yet, just cant get it right.
 
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: Killabot has left the room.
      Back
      Top