How does xBAM.Ball.XXX value works with multi-ball? Which ball does it use?

madmrmax

Weeeeeee
Site Supporters
Joined
Sep 21, 2017
Messages
220
Reaction score
82
Points
35
Favorite Pinball Machine
Indiana Jones (Williams)
In general, how does xBam.Ball.XXX functions work when there are multiple balls on the playfield? Things like xBam.Ball.Velocity? I need to determine the direction a ball hit a trigger, but there could be multiple balls on the table.

thanks,
mark
 
Last edited:
In your trigger hit routine:
Dim Ball
Set Ball = xBAM.BallCloseTo(x,y) where x and y are the coordinates of your trigger
and you test the direction
 
In your trigger hit routine:
Dim Ball
Set Ball = xBAM.BallCloseTo(x,y) where x and y are the coordinates of your trigger
and you test the direction

You could also use additional triggers (placed in each direction the ball can come from towards your trigger) to determine where the ball was coming from. The last trigger that was hit before hitting your trigger would determine this. I do similar with the AIO Example Table's code for the ball rolling functions when the ball enters a ramp, or rolls back down the entrance to the ramp.
 
You could also use additional triggers (placed in each direction the ball can come from towards your trigger) to determine where the ball was coming from. The last trigger that was hit before hitting your trigger would determine this. I do similar with the AIO Example Table's code for the ball rolling functions when the ball enters a ramp, or rolls back down the entrance to the ramp.
It's good for 99,99% of cases. But (OK, this will happen rarely), if your ball (from top) hits the trigger (after hitted the up trigger) and a malicious other ball (from down) was just hitted before your down trigger...
 
It's good for 99,99% of cases. But (OK, this will happen rarely), if your ball (from top) hits the trigger (after hitted the up trigger) and a malicious other ball (from down) was just hitted before your down trigger...

Correct. In multiball cases, I tend to add conditions for if ballsonplayfield > 1 to act differently as a safe guard. It depends on the needs of the table rules, etc.

You can also use ball IDs as well, but I'm not as well versed with how to use that correctly in all cases.
 
I wish Bam would have a function to return a ball object based upon the ball ID given by FP's fpBallID. I could use that in the _Hit event vs. what I would assume is slower "BallCloseTo" function.

Thanks for the answers though @Popotte and @TerryRed. I was surprised by looking in the script in the AIO table that it seems as though most all functions/usages of ball go directly to things like xBam.Ball.Velocity instead of ensuring that it is getting the velocity of the ball which actually is hitting the rubber/post/etc.
 
I wish Bam would have a function to return a ball object based upon the ball ID given by FP's fpBallID. I could use that in the _Hit event vs. what I would assume is slower "BallCloseTo" function.

Thanks for the answers though @Popotte and @TerryRed. I was surprised by looking in the script in the AIO table that it seems as though most all functions/usages of ball go directly to things like xBam.Ball.Velocity instead of ensuring that it is getting the velocity of the ball which actually is hitting the rubber/post/etc.

It does. There is code in there that ID's the different balls, as well as different table items,etc. Otherwise, the code would be no good if more than one ball was on the table. How exactly it works is more up JLou's alley.
 
It does. There is code in there that ID's the different balls, as well as different table items,etc. Otherwise, the code would be no good if more than one ball was on the table. How exactly it works is more up JLou's alley.
Awesome! I do think the Generic_Hit correctly gets the ball speed from BAM. Flipper code currently only assumes one ball on a flipper at a time (I think that's fine cause accuracy with multi-ball flipping is kinda rough).

And the rolling ball sounds do track multi-ball which is awesome!

There are other things in AIO like doing determining the X/Y location for PUP spatial audio in PinMechSound routine that could use updates:

C#:
    If (PUP_SSF_enabled = true and PUP_Status = true) then
        ' if PinMechSound command has these dType, then use ball's x/y position to determine PUP SSF x/y position
        if (dType = "rubber post" or dType = "rubber band" or dType = "metal" or dType = "wood" or dType = "plastic" or dType = "drop target wall" or dType = "apron wall" or dType = "flipper rubber" or dType = "ball" or dType = "playfield") then
            if (xBAM.ball.Position.x > 0 and xBAM.ball.Position.x < xBAM.Table.width and xBAM.ball.Position.y > 0 and xBAM.ball.Position.y < xBAM.Table.length) then
                PUPSoundX = ((xBAM.ball.Position.x/xBAM.Table.width)*20)-10
                PUPSoundY = ((xBAM.ball.Position.y/xBAM.Table.length)*10)*-1
                'AddDebugText "Ball X: " & PUPSoundX : AddDebugText "Ball Y: " & PUPSoundY
            else
                ' ball is positioned outside of the table's dimensions - most likely in a miniplayfield outside the cabinet area (play the PUP SSF sound from the center position)
                PUPSoundX = ((xBAM.Table.width/2)*20)-10
                PUPSoundY = ((xBAM.Table.length/2)*10)*-1
                'AddDebugText "Ball X - MP: " & PUPSoundX : AddDebugText "Ball Y - MP: " & PUPSoundY
            end if
        else    ' for all other PUP SSF events, use the table item's x/y position to determine PUP SSF x/y position
            PUPSoundX = ((fp_item.x/xBAM.Table.width)*20)-10
            PUPSoundY = ((fp_item.y/xBAM.Table.length)*10)*-1
            if SSF_Debug_enabled = true then AddDebugText "PF Item: " & fp_item.Name
        end if

Just minor things that I noticed, not trying to take away from all the awesome code and work that FizX AIO is!

I'm having to look into ball tracking for making a controllable one-way gate and I need to figure out which ball is hitting it, and what to consider if there are multiple balls in the area. That is just making me check out other code that people have written.
 
There are other things in AIO like doing determining the X/Y location for PUP spatial audio in PinMechSound routine that could use updates:

How exactly?
 
Sure!

This part in particular (in the main PinMechSound sub) for mech type, the code is determining PUPSoundX and Y values using the position of the one ball only (from xBAM.ball.Position) which might not even be the ball which is near the object that you want sound generated for.

I would have thought that the PUPSound X and Y values would be positioned relative to the object (fp_item) and not the ball. Just wondering on that.

C#:
            if (xBAM.ball.Position.x > 0 and xBAM.ball.Position.x < xBAM.Table.width and xBAM.ball.Position.y > 0 and xBAM.ball.Position.y < xBAM.Table.length) then
                PUPSoundX = ((xBAM.ball.Position.x/xBAM.Table.width)*20)-10
                PUPSoundY = ((xBAM.ball.Position.y/xBAM.Table.length)*10)*-1
                'AddDebugText "Ball X: " & PUPSoundX : AddDebugText "Ball Y: " & PUPSoundY

Perhaps by taking the X, Y of the FP object and then calling xBAM.BallCloseTo(x,y) with those values you can use that ball's position for spacial audio.
 
Sure!

This part in particular (in the main PinMechSound sub) for mech type, the code is determining PUPSoundX and Y values using the position of the one ball only (from xBAM.ball.Position) which might not even be the ball which is near the object that you want sound generated for.

I would have thought that the PUPSound X and Y values would be positioned relative to the object (fp_item) and not the ball. Just wondering on that.

C#:
            if (xBAM.ball.Position.x > 0 and xBAM.ball.Position.x < xBAM.Table.width and xBAM.ball.Position.y > 0 and xBAM.ball.Position.y < xBAM.Table.length) then
                PUPSoundX = ((xBAM.ball.Position.x/xBAM.Table.width)*20)-10
                PUPSoundY = ((xBAM.ball.Position.y/xBAM.Table.length)*10)*-1
                'AddDebugText "Ball X: " & PUPSoundX : AddDebugText "Ball Y: " & PUPSoundY

That section is only being used for FizX's autogenerated "ball hits" and nothing else. So that section will only use the position of the ball to determine the x/y position for pup ssf. (as intended)

The dtype is what determines when to use that section. There are specific dtypes (rubber post, rubber band, etc) which are set aside only for FizX's auto-generated ball hit sounds (based on material, specific names, etc). They also determine what kind is sound is automatically used by FizX.


All other instances of pinmechsound use the fp_item (which is specified in the pinmechsound commands) to determine the x/y position of the pup ssf sound.

(as described in that sub)
 
Last edited:
That section is only being used for FizX's autogenerated "ball hits" and nothing else. So that section will only use the position of the ball to determine the x/y position for pup ssf. (as intended)

The dtype is what determines when to use that section. There are specific dtypes (rubber post, rubber band, etc) which are set aside only for FizX's auto-generated ball hit sounds (based on material, specific names, etc). They also determine what kind is sound is automatically used by FizX.


All other instances of pinmechsound use the fp_item (which is specified in the pinmechsound commands) to determine the x/y position of the pup ssf sound.

(as described in that sub)
Awesome. Thanks!
 
It seems to me to understand, that you want to direct a ball where you want, with the function ball.SetVelocity,right?
I'm talking HERE which unfortunately I forgot to update, I had to put the code, anyway and this works via "invisible wall" I don't know if it also works with a trigger.
Sub LeftSlingshotRubber1_Hit()
If (fpTilted = FALSE) Then
Playsound "xx"
AddScore(xxx)
RubberLeft.SolenoidPulse()
Dim ball
Set ball = xBAM.BallCloseTo(0,0)
Dim vc
Dim ag
ag = 51 * DegToRad 'angolo
vc = 900 'velocità
ball.SetVelocity vc*sin(ag),- vc*cos(ag), 0
End if
End Sub


Const RadToDeg = 57.295779513082320876798154814105
Const DegToRad = 0.01745329251994329576923690768489

The "51/900" values are:
51= it's the angle you want the ball to take
900=
it is the speed of the ball, the more you increase it the faster the ball.

regards
 
Last edited:
It seems to me to understand, that you want to direct a ball where you want, with the function ball.SetVelocity,right?
I'm not talking HERE which unfortunately I forgot to update, I had to put the code, anyway and this works via "invisible wall" I don't know if it also works with a trigger.


The "51/900" values are:
51= it's the angle you want the ball to take
900=
it is the speed of the ball, the more you increase it the faster the ball.

regards
Thanks Paolo! I just now updated the thread title to better reflect my question. I was trying to understand in multi-ball scenarios, what ball do the xBam.Ball.XXX functions apply to?
 
Thanks Paolo! I just now updated the thread title to better reflect my question. I was trying to understand in multi-ball scenarios, what ball do the xBam.Ball.XXX functions apply to?
Sorry but I don't understand, what do you mean by xBam.Ball.XXX? or rather which xbam code are you referring to....?
I can't connect what do you mean in multiball scenarios the codes xBam.Ball.XXX.......probably if we don't talk about xBam.Ball.Velocity so it's something I don't know,sorry again.
 
Sorry but I don't understand, what do you mean by xBam.Ball.XXX? or rather which xbam code are you referring to....?
I can't connect what do you mean in multiball scenarios the codes xBam.Ball.XXX.......probably if we don't talk about xBam.Ball.Velocity so it's something I don't know,sorry again.
Totally fine!

the "XXX" is referring to any of the BAM BallInfo functions/properties when I access the BallInfo via xBam.Ball.

BallInfo properties are:
C#:
BallInfo (from xBAM.Ball or xBAM.BallCloseTo)
    .Position
        .x
        .y
        .z
    .PositionGlobal
        .x
        .y
        .z
    .Velocity
        .x
        .y
        .z
    .Speed
    .HitSpeed
    .Exist
    .ExtInt1   (can be SET or READ)
    .ExtInt2   (can be SET or READ)
    .ExtInt3   (can be SET or READ)
    .ExtFloat1 (can be SET or READ)
    .ExtFloat2 (can be SET or READ)
    .ExtFloat3 (can be SET or READ)
    .Id        (READ only)
    .Name      (can be SET or READ)
    .UpdateBall Red, Green, Blue, DirtTexture, ReflectionTexturem, ReflectionInPlayfield
    .Opacity   (only SET)
    .SetBallOpacityWithEasing opacity, time, easingFunction
    .ExtTimer1 (READ only)
    .ExtTimer2 (READ only)
    .ExtTimer3 (READ only)
    .ResetExtTimer idx  (idx = 1, 2, 3)
    .StopExtTimer idx   (idx = 1, 2, 3)
 
Forum activity
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.
      Mibs Mibs: StevOz has posted a new reply in the thread "A Random solution.".
      Back
      Top