Script to simulate uneven playfield

FireDragon76

Pinball Wizard
Joined
Apr 5, 2023
Messages
137
Reaction score
19
Points
18
Favorite Pinball Machine
Spirit of 76
I am trying to create a script to simulate an uneven playfield. I am using Chat GPT to help me. It suggests the following script:

Code:
Sub ApplyRandomImpulseToBall()

    Const IMPULSE_MIN = -0.01  ' Minimum impulse value

    Const IMPULSE_MAX = 1  ' Maximum impulse value

    Const IMPULSE_INTERVAL = 0.01  ' Interval to apply impulse (in seconds)


    Static lastImpulseTime


    ' Check if enough time has passed to apply a new impulse

    If Timer - lastImpulseTime >= IMPULSE_INTERVAL Then

        ' Generate random impulse values for x and y axis

        Dim impulseX, impulseY

        impulseX = Rnd() * (IMPULSE_MAX - IMPULSE_MIN) + IMPULSE_MIN

        impulseY = Rnd() * (IMPULSE_MAX - IMPULSE_MIN) + IMPULSE_MIN


        ' Apply impulse to the ball's velocity

        Ball.VelX = Ball.VelX + impulseX

        Ball.VelY = Ball.VelY + impulseY


        ' Update last impulse time

        lastImpulseTime = Timer

    End If

End Sub


' Call ApplyRandomImpulseToBall() function in Future Pinball's main loop

Sub UpdatePhysics()

    ' Add your game logic here

    ApplyRandomImpulseToBall()

End Sub

Can anybody else confirm if this code works? I can't seem to notice.
 
I don't know. I am surprised it came up with something that does not generate errors. The best way to test it is to add some extreme values to the constants. Then you will notice if it actually does something.
 
I don't know. I am surprised it came up with something that does not generate errors. The best way to test it is to add some extreme values to the constants. Then you will notice if it actually does something.

The script compiles, though I had to remove the 'static" descriptor from the 5th line as it wasn't recognized by the compiler.

I am just starting to learn scripting with visual basic.
 
Constants are the values in red below:

Const IMPULSE_MIN = -0.01 ' Minimum impulse value

Const IMPULSE_MAX = 1 ' Maximum impulse value

Const IMPULSE_INTERVAL = 0.01 ' Interval to apply impulse (in seconds)
 
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: paskite has left the room.
      Back
      Top