Jump to content



Photo
- - - - -

Reconstructing an SS Pinball Machine for FP


  • Please log in to reply
63 replies to this topic

#41 MeatBundle

MeatBundle

    Enthusiast

  • Members
  • PipPipPip
  • 71 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted 25 April 2010 - 10:25 PM

Disclaimer: this may not be final code, but it will work.

Everything on an FP table that does something (i.e. not a wall) needs to have a class built for it. To start with, you simply need a class declaration, which looks like this:

CODE
Class bumper
End Class


Of course this class doesn't actually do anything, we still have to add in the properties and methods that make it work. Since it is a simple class, I think it will actually only have one property:

CODE
Class bumper
    Public State
End Class


To use this class, you have to "instantiate" the class, which is just a programming way of saying that you have to create an object of type "bumper". This will be done in the FuturePinball_BeginPlay() subroutine. We do this because we have to create all of our objects when the table first loads so that everything will work when the player starts the game. The way it is done is thusly:

CODE
Dim redBumper
set redBumper = bumper


I'm also going to create a blueBumper and yellowBumper object as well.

To change the value of the "State" property, you simply use the object name and the "." operator, like this:

CODE
redBumper.State = "lit"


Notice that I'm using text to tell the program if the bumper is off, lit, or flashing. The code itself doesn't care. You can use text or numbers equally well here. The reason I'm using text in this case is for readability. I can look at "lit" and know what that means, whereas if it was written as redBumper.State = 2, I might not know what that means.

So to pull it all together, here is the way that the bumper logic will work with classes. Since we have to rely on the built-in _Hit() functions, we will use that to call our own scoring function:
CODE
Sub redBump_Hit()
    bumpHit(redBumper)
End Sub

And our function will look like this:
CODE
Sub bumpHit( bump)
    Dim numFlashing : numFlashing = 0

    If (bump.State = "off") then
        AddScore(1000)
    Else
        If (bump.State = "lit) then
            AddScore(2000)
        Else
            Dim i
            For i = 1 to 3
                Select Case (i)
                    case 1: if (redBumper.State = "flashing") then
                                   numFlashing = numFlashing + 1
                               end if
                    case 2: if (blueBumper.State = "flashing") then
                                   numFlashing = numFlashing + 1
                               end if
                    case 3: if (yellowBumper.State = "flashing") then
                                   numFlashing = numFlashing + 1
                End Select
            Next
            If (numFlashing = 3) then
                AddScore(5000)
            Else
                AddScore(3000)
            End If
        End If
    End If    
End Sub


I understand that the final code may look more complicated than the code in the previous post, and in some ways it is. The bumpers are actually the worst case scenario for classes. A lot of setup without much apparent benefit. But as things get more complicated, the benefits become more clear. To start off, we decreased the number of variables that we were using, and consolidated functions. Instead of having three seperate functions for each bumper, we call the same function for all three. This means that if we want to change the bumper behavior for some reason, we just change it in once place, not in three.

I do realize that the earlier post's function could be simplified in the same manner, but I wasn't after perfect code in that function, it was for illustrative purposes only, and thus was written with clarity in mind.

Edited by MeatBundle, 11 May 2010 - 09:35 PM.


#42 MeatBundle

MeatBundle

    Enthusiast

  • Members
  • PipPipPip
  • 71 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted 11 May 2010 - 09:35 PM

Well my laptop died and I had to get a new computer. All of my work was on the laptop hard drive, so I'll have to order an adapter to hook the laptop hard drive into my desktop. Hopefully the data is still intact and it will transfer successfully. Fingers are crossed.

#43 Rawd

Rawd

    Pinball Wizard

  • VIP
  • 4,313 posts
  • Location:Edmonton, Canada

  • Flag: Canada

  • Favorite Pinball: Triple Strike



Posted 11 May 2010 - 11:22 PM

QUOTE (MeatBundle @ May 11 2010, 03:35 PM) <{POST_SNAPBACK}>
Well my laptop died and I had to get a new computer. All of my work was on the laptop hard drive, so I'll have to order an adapter to hook the laptop hard drive into my desktop. Hopefully the data is still intact and it will transfer successfully. Fingers are crossed.


Oh man! You should be able to retrieve the data.

I always backup my stuff to 2 different HD's (sometimes 3). I had 5 HD's fail on me within a year a few years back, and I learned my lesson. Good luck.



 


#44 Pinbotic

Pinbotic

    Enthusiast

  • VIP
  • 290 posts
  • Location:Canada

  • Flag: Canada

  • Favorite Pinball: Pin*Bot




  • Trophies:

Posted 11 May 2010 - 11:27 PM

QUOTE (Rawd @ May 11 2010, 07:22 PM) <{POST_SNAPBACK}>
QUOTE (MeatBundle @ May 11 2010, 03:35 PM) <{POST_SNAPBACK}>
Well my laptop died and I had to get a new computer. All of my work was on the laptop hard drive, so I'll have to order an adapter to hook the laptop hard drive into my desktop. Hopefully the data is still intact and it will transfer successfully. Fingers are crossed.


Oh man! You should be able to retrieve the data.

I always backup my stuff to 2 different HD's (sometimes 3). I had 5 HD's fail on me within a year a few years back, and I learned my lesson. Good luck.


5 HD failures! ohmy.gif You must have the worst of luck. I have my fingers crossed too for you, MeatBundle, hopefully you will recover everything because that table was looking great.

Avatar courtesy of Grizz.

#45 Rawd

Rawd

    Pinball Wizard

  • VIP
  • 4,313 posts
  • Location:Edmonton, Canada

  • Flag: Canada

  • Favorite Pinball: Triple Strike



Posted 11 May 2010 - 11:32 PM

QUOTE (Pinbotic @ May 11 2010, 05:27 PM) <{POST_SNAPBACK}>
5 HD failures! ohmy.gif You must have the worst of luck. I have my fingers crossed too for you, MeatBundle, hopefully you will recover everything because that table was looking great.


Ya, 4 Seagates, and a Western Digital in a matter of 8 or 9 months. This was 3 or 4 years ago, and I had nothing fail before or since.

I really hope that you can get that info! It is a great table... How does a Laptop HD work? Will the pc power up?


 


#46 MeatBundle

MeatBundle

    Enthusiast

  • Members
  • PipPipPip
  • 71 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted 04 July 2010 - 02:16 AM

Ok I got a new computer, and turns out my laptop hard drive was plug n play into the new computer, so I was able to recover all of my files. Started working on coding some more, should be able to show some coding soon. It's coming along fast so far, but I realize that the basic outlines of the code are the easy parts. The hard parts are all of the little details that make the table come alive and feel like the real thing. This applies to the code as well as the graphics, because the code calls all of the lighting, sound, and gas segment display effects for the table, and if it isn't right, it will be noticeable.

#47 Mystman

Mystman

    Enthusiast

  • Members
  • PipPipPip
  • 93 posts

  • Flag: Netherlands

  • Favorite Pinball: Sonic 2

Posted 04 July 2010 - 07:56 AM

Cool thread. =)

Can I ask why you're using the "select case" inside of a for-loop in the bumphit sub (post 41)?

I can see how it works.. but wouldn't it also work if you just had

CODE
                    if (redBumper.State = "flashing") then
                                   numFlashing = numFlashing + 1
                               end if
                    if (blueBumper.State = "flashing") then
                                   numFlashing = numFlashing + 1
                               end if
                    if (yellowBumper.State = "flashing") then
                                   numFlashing = numFlashing + 1
                               end if


?

#48 destruk

destruk

    VPF Veteran

  • VPF Staff
  • 6,338 posts
  • Location:Colorado Springs, CO

  • Flag: United States of America

  • Favorite Pinball: Ultrapin!



Posted 04 July 2010 - 10:06 AM

I'm sure everyone would code that differently.
From your code you want to award one thing if all three bumpers are flashing, and if they aren't then you award a different thing.

For those conditions, a simple

If redBumper.State = "flashing" And blueBumper.State = "flashing" And yellowBumper.State = "flashing" Then
AddScore 5000
Else
AddScore 3000
End If

would accomplish the same thing.

And I disagree, making unnecessary classes, while it makes your code look 'pretty' doesn't make it any more efficient. It makes it more confusing to troubleshoot.
"Everything on an FP table that does something (i.e. not a wall) needs to have a class built for it."
That is simply your preference.

It'll be cool to play this when it's done Meatbundle.

Edited by destruk, 04 July 2010 - 10:12 AM.

Build a fire, vipers love the heat.


#49 TheNalex

TheNalex

    Enthusiast

  • VIP
  • 115 posts

  • Flag: France

  • Favorite Pinball: Terminator 2

Posted 04 July 2010 - 11:00 AM

QUOTE (Rawd @ May 12 2010, 01:22 AM) <{POST_SNAPBACK}>
QUOTE (MeatBundle @ May 11 2010, 03:35 PM) <{POST_SNAPBACK}>
Well my laptop died and I had to get a new computer. All of my work was on the laptop hard drive, so I'll have to order an adapter to hook the laptop hard drive into my desktop. Hopefully the data is still intact and it will transfer successfully. Fingers are crossed.


Oh man! You should be able to retrieve the data.

I always backup my stuff to 2 different HD's (sometimes 3). I had 5 HD's fail on me within a year a few years back, and I learned my lesson. Good luck.


This kind of failures are, most of the time, caused by another component of your computer (probably the power supply).

Alex
Webmaster of FPRelease

#50 MeatBundle

MeatBundle

    Enthusiast

  • Members
  • PipPipPip
  • 71 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted 04 July 2010 - 12:43 PM

QUOTE (TheNalex @ Jul 4 2010, 03:00 PM) <{POST_SNAPBACK}>
QUOTE (Rawd @ May 12 2010, 01:22 AM) <{POST_SNAPBACK}>
QUOTE (MeatBundle @ May 11 2010, 03:35 PM) <{POST_SNAPBACK}>
Well my laptop died and I had to get a new computer. All of my work was on the laptop hard drive, so I'll have to order an adapter to hook the laptop hard drive into my desktop. Hopefully the data is still intact and it will transfer successfully. Fingers are crossed.


Oh man! You should be able to retrieve the data.

I always backup my stuff to 2 different HD's (sometimes 3). I had 5 HD's fail on me within a year a few years back, and I learned my lesson. Good luck.


This kind of failures are, most of the time, caused by another component of your computer (probably the power supply).

Alex


Actually the video card died, not the hard drive. But since I couldn't see anything, it makes it hard to do anything biggrin.gif.

QUOTE (destruk @ Jul 4 2010, 02:06 PM) <{POST_SNAPBACK}>
I'm sure everyone would code that differently.
From your code you want to award one thing if all three bumpers are flashing, and if they aren't then you award a different thing.

For those conditions, a simple

If redBumper.State = "flashing" And blueBumper.State = "flashing" And yellowBumper.State = "flashing" Then
AddScore 5000
Else
AddScore 3000
End If

would accomplish the same thing.


Yes this is the final code I'm using now. Don't remember why I used the Select Case part in there...I think I was thinking something about the states not being saved or something, not sure, but that earlier code isn't the best way. It would work, just isn't the best way.

QUOTE
And I disagree, making unnecessary classes, while it makes your code look 'pretty' doesn't make it any more efficient. It makes it more confusing to troubleshoot.
"Everything on an FP table that does something (i.e. not a wall) needs to have a class built for it."
That is simply your preference.


I agree if it's really simple things (like the 50k target in ES won't have a class, because it's so simple). The rest comes down to preference, like you said.

#51 vartaxe

vartaxe

    Hobbyist

  • Members
  • PipPip
  • 42 posts
  • Location:Portugal

  • Flag: Portugal

  • Favorite Pinball: Terminator 2

Posted 05 July 2010 - 12:30 PM

great thread! dblthumb.gif

#52 Rawd

Rawd

    Pinball Wizard

  • VIP
  • 4,313 posts
  • Location:Edmonton, Canada

  • Flag: Canada

  • Favorite Pinball: Triple Strike



Posted 05 July 2010 - 04:48 PM

QUOTE (Rawd @ May 11 2010, 05:22 PM) <{POST_SNAPBACK}>
QUOTE (MeatBundle @ May 11 2010, 03:35 PM) <{POST_SNAPBACK}>
Well my laptop died and I had to get a new computer. All of my work was on the laptop hard drive, so I'll have to order an adapter to hook the laptop hard drive into my desktop. Hopefully the data is still intact and it will transfer successfully. Fingers are crossed.


Oh man! You should be able to retrieve the data.

I always backup my stuff to 2 different HD's (sometimes 3). I had 5 HD's fail on me within a year a few years back, and I learned my lesson. Good luck.


Since I made this post, I dropped a 500GB HD on my office floor and it no longer spins up sad.gif I didn't have alot of it backed up and I lost a ton of personal videos and photos. sad.gif



 


#53 MeatBundle

MeatBundle

    Enthusiast

  • Members
  • PipPipPip
  • 71 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted 06 July 2010 - 11:17 AM

QUOTE (Rawd @ Jul 5 2010, 08:48 PM) <{POST_SNAPBACK}>
Since I made this post, I dropped a 500GB HD on my office floor and it no longer spins up sad.gif I didn't have alot of it backed up and I lost a ton of personal videos and photos. sad.gif


Wow you are jinxed...that's awful

#54 MeatBundle

MeatBundle

    Enthusiast

  • Members
  • PipPipPip
  • 71 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted 10 July 2010 - 05:30 PM

Work is progressing at a steady rate on coding the table. As mentioned before, I've taken the complete script from the Bad Cats table by Uncle Willy, and am modifying it to work with Earthshaker.

On one hand it's great for a lot of the background work to already have been done. Routines for the gas segment display, software timers, light effects, and menu adjustments are ready to go with just a few adjustments. It's all the underlying things that make the table feel realistic, and I'm glad I don't have to code all of that.

On the other hand, it's a lot to wrap your head around at one time, so I'm doing things in pieces. While writing the bumper code I realized that I needed to know how the menu adjustment class worked. So I jumped into that, and got the menu changed from Bad Cats over to Earthshaker. Then I started writing the code for the Billboard drop targets, and realized that I needed to know how the timer classes worked, as well as the light classes to insure that the proper lighting effects are running after each target is hit. So I learned those as well, and am starting to get a good grasp of what the Propst Engine is capable of.

The classes in place are a great framework. They free me from having to code a lot of the tedious parts of the table, and let me concentrate on table logic, correct displays, and authentic lighting effects.

Hopefully by the end of the day I'll have a completed class that I can post up here and show you. Right now I have most of the basic things completed for the table, just have to flesh out each system with correct displays, lighting effects, and sounds. Haven't yet started on the ramps or the multiball modes, as those are the most complex parts of the table. I generally like to save the best for last.



#55 MeatBundle

MeatBundle

    Enthusiast

  • Members
  • PipPipPip
  • 71 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted 10 July 2010 - 09:39 PM

So, barring any bugs that may be found, here is the final code for the bumper class:

CODE
'-----------------------------------CLASS bumperHandler-----------------------------------
' Handles the bumpers. The bumpers score differing points depending on whether they are lit,
'     flashing, or off.
'
' Debug id:
' Script object names: objBumperHandler
' Timers: -
' Lights: -
'-----------------------------------------------------------------------------------
Class bumperHandler

    'Possible states are off, lit, flashing. Using state variables instead of using the bulb status of the bumpers to avoid bad logic due to lighting effects.
    Public rbState                'state for red bumper
    Public bbState                'blue bumper
    Public ybState                'yellow bumper

    Public Sub Reset()
        'Resets after each ball, and between players. Adjustable setting via In-Game menu
        Select Case (objSettings.BumpStart)
            Case "ALL OFF":
                                rbState = "off"
                                bbState = "off"
                                ybState = "off"
            Case "1 ON":
                                rbState = "lit"
                                bbState = "off"
                                ybState = "off"
            Case "2 ON":
                                rbState = "lit"
                                bbState = "lit"
                                ybState = "off"
            Case "ALL ON":
                                rbState = "lit"
                                bbState = "lit"
                                ybState = "lit"
            Case "1 BLINK":
                                rbState = "flashing"
                                bbState = "lit"
                                ybState = "lit"
            Case "2 BLINK":
                                rbState = "flashing"
                                bbState = "flashing"
                                ybState = "lit"
            Case "ALL BLINK":
                                rbState = "flashing"
                                bbState = "flashing"
                                ybState = "flashing"
        End Select

        'Set the lights
        setBumpLights()

    End Sub

    Public Sub NewRound()
        Reset()
    End Sub

    Public Sub setBumpLights()

        'Set bumper lights
        Select Case (rbState)
            Case "off":    redBumper.State = bulbOff
            Case "lit":    redBumper.State = bulbOn
            Case "flashing":    redBumper.State = bulbBlink
        End Select

        Select Case (bbState)
            Case "off":    blueBumper.State = bulbOff
            Case "lit":    blueBumper.State = bulbOn
            Case "flashing":    blueBumper.State = bulbBlink
        End Select

        Select Case (ybState)
            Case "off":    yellowBumper.State = bulbOff
            Case "lit":    yellowBumper.State = bulbOn
            Case "flashing":    yellowBumper.State = bulbBlink
        End Select

    End Sub

    Public Sub bumpHit(number)

        Dim state
        ' Get state of bumper that was hit
        Select case (number)
            case 1: state = rbState
            case 2: state = bbState
            case 3: state = ybState
        End Select

        If (state = "off") then
            objPlayer.AddScore(1000)
        Else
            If (state = "lit") then
                objPlayer.AddScore(2000)
            Else
                'If they are all flashing, score 5000
            If (rbState = "flashing" AND bbState = "flashing" AND ybState = "flashing") then
                objPlayer.AddScore(5000)
            Else
                    'If this one is flashing, but not all of them, only score 3000
                objPlayer.AddScore(3000)
            End If
        End If
        End If    

    End Sub

End Class


I know it's a bit much to read at one time, but I tried to comment it well, and should be self-explainatory for the most part. The bumpers themselves are coded thusly:

CODE
'----------------BUMPERS-------------------
Sub redBumper_Hit()
    If (State>=30) then
        objBalls.RegisterBall()
        objBumperHandler.bumpHit(1)
    Else
        redBumper.SolenoidOff()
    End if
End Sub

Sub blueBumper_Hit()
    If (State>=30) then
        objBalls.RegisterBall()
        objBumperHandler.bumpHit(2)
    Else
        blueBumper.SolenoidOff()
    End if
End Sub

Sub yellowBumper_Hit()
    If (State>=30) then
        objBalls.RegisterBall()
        objBumperHandler.bumpHit(3)
    Else
        yellowBumper.SolenoidOff()
    End if
End Sub


The only thing here that I haven't talked about (I think) is the objBalls.RegisterBall() line. The objBalls object keeps track of where all the balls are in the game, just like a real pinball table would. It will trigger a message on the display if one of the balls is missing, and do a ball search routine if no triggers are hit after a specified amount of time. Thus, the objBalls.RegisterBall() just tells the objBalls "object" that the ball just hit a bumper, and then it will reset it's internal timer for the ball search routine.

Any questions or feedback/tips, let me know.

#56 destruk

destruk

    VPF Veteran

  • VPF Staff
  • 6,338 posts
  • Location:Colorado Springs, CO

  • Flag: United States of America

  • Favorite Pinball: Ultrapin!



Posted 10 July 2010 - 10:32 PM

nevermind. I still think that's a whole lot of code that could be condensed, more legible, and easier to work with.

Edited by destruk, 10 July 2010 - 10:34 PM.

Build a fire, vipers love the heat.


#57 Popotte

Popotte

    Pinball Fan

  • VIP
  • 813 posts
  • Location:Paris

  • Flag: France

  • Favorite Pinball: World Fair



Posted 10 July 2010 - 10:37 PM

QUOTE (destruk @ Jul 11 2010, 12:32 AM) <{POST_SNAPBACK}>
nevermind. I still think that's a whole lot of code that could be condensed, more legible, and easier to work with.

Me too... But nice work, MeatBundle!

Les cons ça ose tout. C'est même à ça qu'on les reconnaît.

PopotteDMDredo.gif

 


#58 MeatBundle

MeatBundle

    Enthusiast

  • Members
  • PipPipPip
  • 71 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted 10 July 2010 - 10:46 PM

QUOTE (Popotte @ Jul 11 2010, 02:37 AM) <{POST_SNAPBACK}>
QUOTE (destruk @ Jul 11 2010, 12:32 AM) <{POST_SNAPBACK}>
nevermind. I still think that's a whole lot of code that could be condensed, more legible, and easier to work with.

Me too... But nice work, MeatBundle!


I'd love to hear ideas. I'm all about making things easier.

#59 destruk

destruk

    VPF Veteran

  • VPF Staff
  • 6,338 posts
  • Location:Colorado Springs, CO

  • Flag: United States of America

  • Favorite Pinball: Ultrapin!



Posted 10 July 2010 - 10:54 PM

Something like this, even though it doesn't use classes, would be just as functional as your code there.

CODE
Dim BumperArray,Bumper1(4),Bumper2(4),Bumper3(4),X

Sub FuturePinball_BeginPlay
SetupFactoryBumpers
End Sub

Sub SetupFactoryBumpers
For X=1 To 4 '4 players 'set defaults
Select Case FactoryBumpSetting
Case 1:Bumper1(X)=0:Bumper2(X)=0:Bumper3(X)=0
Case 2:Bumper1(X)=1:Bumper2(X)=0:Bumper3(X)=0
Case 3:Bumper1(X)=1:Bumper2(X)=1:Bumper3(X)=0
Case 4:Bumper1(X)=1:Bumper2(X)=1:Bumper3(X)=1
Case 5:Bumper1(X)=2:Bumper2(X)=0:Bumper3(X)=0
Case 6:Bumper1(X)=2:Bumper2(X)=2:Bumper3(X)=0
Case 7:Bumper1(X)=2:Bumper2(X)=2:Bumper3(X)=2
End Select
Next
End Sub

BumperArray=Array(RedBumper,BlueBumper,YellowBumper)

Sub RedBumper_Hit:CheckBumperHit 0:End Sub
Sub BlueBumper_Hit:CheckBumperHit 1:End Sub
Sub YellowBumper_Hit:CheckBumperHit 2:End Sub

Sub CheckBumperHit(BumperName) 'accounts for every possible case per the rulesheet
If RedBumper.State=2 And BlueBumper.State=2 And YellowBumper.State=2 Then
    AddScore 5000
Else
If BumperArray(BumperName).State=0 Then AddScore 1000
If BumperArray(BumperName).State=1 Then AddScore 2000
If BumperArray(BumperName).State=2 Then AddScore 3000
End If
End Sub


Then you simply save the state of the bumper variables when a ball is lost, and restore the state when the same player is back up again. When a game starts, simply check the player number and set the bumpers using RedBumper.State=bumper1(PlayerNumber):BlueBumper.State=Bumper2(PlayerNumber):Yel
lowBumper.State=Bumper3(PlayerNumber)
I think you'll want to save more than simply the bumper lights when the player changes.
Of course what is easy for me might not be for you - just a different coding style.

(corrected array access)

Edited by destruk, 10 July 2010 - 10:56 PM.

Build a fire, vipers love the heat.


#60 MeatBundle

MeatBundle

    Enthusiast

  • Members
  • PipPipPip
  • 71 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted 10 July 2010 - 11:08 PM

I like the compact nature of your code, I just find it a bit harder to read. It seems to be more professionally written, although not having looked at any professional code I can't say that for sure. Thanks for the input, I might be able to rearrange some of my code a bit. I'm still stuck on using classes though, so won't be changing it as drastically as you did here. In Earthshaker, the bumpers reset after every ball/player, so I think the code you posted is all that's required.