Jump to content



Photo
- - - - -

Unique Drop Target Sounds [SOLVED]


  • Please log in to reply
8 replies to this topic

#1 SpectreRose

SpectreRose

    Hobbyist

  • Members
  • PipPip
  • 28 posts

  • Flag: ---------

  • Favorite Pinball: I love too many I can't decide!

Posted 22 April 2015 - 02:52 PM

I know I've been asking a lot of questions of you guys lately, but I still don't consider myself much of a programmer since most problems I come across aren't ones I know the answers to (or can easily find solutions for).

 

That said, I have a situation where I want to implement a different sound every time a drop target in a particular bank is hit.

 

Example: 4 Bank Drop Targets - The first one hit plays Sound1 (It doesn't necessarily have to be DropTarget1). The second one hit will play Sound2, unless Sound1 is still playing. (I imagine I'll have to use a Timer for this.) Then the third will play Sound3, unless still muted by MuteTimer1 or 2. The fourth one at this time doesn't have any sound so don't worry about that.

 

I figure it must use a Select Case in there somewhere, but I wouldn't know how to tell the script to do it this way. Any ideas?

 

As always, I appreciate the help you guys have been providing.

 

 

UPDATE:

 

For anyone who has been following this, I figured out the problem. I wanted to use a nested variable local to the specific subroutine, however that was not working as intended. Every time the Drop Targets got hit, they would only count to 1, even if they were supposedly directed to increment higher.

 

Instead, I changed the local "Dim HitCount" into a Global "Dim DT1HitCount". I don't know why, but it's working like this now.

 

That said, Here is my solution:

Sub DropTarget1_hit()

    DT1HitCount = (DT1HitCount + 1)

    If (DT1HitCount = 1) Then
        PlaySound "vo_Help1"
        DT1Mute1.Enabled = TRUE        'DT1Mute is a Timer'
    Else
        If (DT1HitCount = 2) AND DT1Mute1.Enabled = FALSE Then
            PlaySound "vo_Help2"
            DT1Mute2.Enabled = TRUE
        Else
            If (DT1HitCount = 3) AND DT1Mute1.Enabled = FALSE AND DT1Mute2.Enabled = FALSE Then
                PlaySound "vo_Help3"
            Else
                If (DT1Hitcount = 4) Then
                   'I can add something here later...'
                End If
            End If
        End If
    End If

    Select Case(fpEventID)
        Case 1: DT1Light1.state = BulbOn
        Case 2: DT1Light2.state = BulbOn
        Case 3: DT1Light3.state = BulbOn
        Case 4: DT1Light4.state = BulbOn
    End Select

    If(DropTarget1.dropped = TRUE) Then
        AddScore(5000)
        DT1Timer1.Enabled = TRUE
        DT1Timer2.Enabled = TRUE
    Else
        AddScore(500)
    End If

End Sub

Sub DT1Timer1_Expired()

    'This one plays a sound and makes the lights flash, warning the player that a reset is incoming.'
    DT1Timer1.Enabled = FALSE
    PlaySound "vo_Reset", (SoundVolume)
    DT1Light1.state = BulbBlink
    DT1Light2.state = BulbBlink
    DT1Light3.state = BulbBlink
    DT1Light4.state = BulbBlink

End Sub

' Here is where the Drop Targets reset, including the DT1HitCount.'
Sub DT1Timer2_Expired()

    DT1Timer2.Enabled = FALSE
    DT1Light1.FlashForMS 100, 50, BulbOff
    DT1Light2.FlashForMS 100, 50, BulbOff
    DT1Light3.FlashForMS 100, 50, BulbOff
    DT1Light4.FlashForMS 100, 50, BulbOff
    DT1Target1.SolenoidPulse()
    DT1HitCount = 0
    PlaySound "DropTargetReset"

End Sub

' The following Mute Timers keep sound from playing on top of each other.' 
' The timer interval is set to last the duration of the selected sound.'
Sub DT1Mute1_Expired()
    
    DT1Mute1.Enabled = FALSE

End Sub

Sub DT1Mute2_Expired()

    DT1Mute2.Enabled = FALSE

End Sub

Also, I nested each increment of DT1HitCount to save space and tidy it up a little.


Edited by SpectreRose, 28 April 2015 - 07:06 AM.


#2 maffewl

maffewl

    Enthusiast

  • Members
  • PipPipPip
  • 99 posts

  • Flag: United States of America

  • Favorite Pinball: Attack From Mars / Guns 'N Roses

Posted 22 April 2015 - 03:59 PM

I'm learning this scripting as I go as well, but I would probably set it up as a "Select Case" with either a random number or down the line (whichever you are looking for).  However, instead of using several timers, I would a timer, such as "SoundTimer" and create 2 variables.  I.e., I would create a "LastSoundWas" variable and set it to 0 to start, then in each case change that variable to the current case number.  So "Case 1" would set the variable to "LastSoundWas = 1".  The second variable would let the program know that a sound is currently active with something like "IsSoundActive", and 0 is no, and 1 is yes.  Then have If/Then that statements to say if "LastSoundWas = 1" re-call the routine and go to 2, as well as  if a sound is active, i.e., "IsSoundActive = 1", then nothing happens.

 

It would look something like this:

 

Dim LastSoundWas

Dim IsSoundActive

 

LastSoundWas = 0

IsSoundActive = 0

 

Sub BankTargets_Hit()  '<--- Or however you set up bank targets, which I haven't done

  If (IsSoundActive = 0) Then

    SoundTimer.Set True, 1000 '<--- Or however long for the timer

      Select Case (RandomNumber)

        Case 1

          If (LastSoundWas = 1) Then

           BankTargets_Hit()

         Else

           IsSoundActive = 1

           Playsound "whatever"

           LastSoundWas = 1

         End If

       Case 2

         If (LastSoundWas = 2) Then

           BankTargets_Hit()

         Else

           IsSoundActive = 1

           Playsound "whatever"

           LastSoundWas = 2

         End If

    ... and so on ...

  End If

End Sub

 

Sub SoundTimer_Expired()

SoundTimer.Enabled = False

IsSoundActive = 0

End Sub

 

Again, I'm still learning, but I would play around with something like this.  Maybe it's too complex, and if so, I'd be curious to learn other preferred methods.  Also, the syntax may need some massaging as I'm typing this quickly, but play around with it.

 

Cheers!


Edited by maffewl, 22 April 2015 - 04:04 PM.


#3 SpectreRose

SpectreRose

    Hobbyist

  • Members
  • PipPip
  • 28 posts

  • Flag: ---------

  • Favorite Pinball: I love too many I can't decide!

Posted 26 April 2015 - 02:14 AM

Been trying to work with this kind of frame work. Couldn't make something work with it. Sorry. Maybe it's just me?



#4 SpectreRose

SpectreRose

    Hobbyist

  • Members
  • PipPip
  • 28 posts

  • Flag: ---------

  • Favorite Pinball: I love too many I can't decide!

Posted 26 April 2015 - 10:11 PM

Maybe I should see about a script that records the number of hits a particular object has taken. I have two other objects that require such a script, and I think I could link the number of hits to specific actions before resetting the count to zero. However in this case, I seem to have trouble getting the script to do things when my number reaches a certain point.



#5 SpectreRose

SpectreRose

    Hobbyist

  • Members
  • PipPip
  • 28 posts

  • Flag: ---------

  • Favorite Pinball: I love too many I can't decide!

Posted 27 April 2015 - 07:23 AM

Okay... So after doing a LOT of reading, I seem to have a general idea about how I want this to go down, however for some reason it's not working as intended. Here's what I got:

Sub DropTarget1_hit()

Dim HitCount

    HitCount = HitCount + 1

    If (HitCount = 1) Then
        TestLight1.State = BulbOn   'TestLights tells me if the HitCount is rising as I want it to'
        PlaySound "vo_Help1"
        Mute1.Enabled = TRUE        'Mute is a Timer'
    End If

    If (HitCount = 2) AND Mute1.Enabled = FALSE Then
        TestLight2.State = BulbOn
        PlaySound "vo_Help2"
        Mute2.Enabled = TRUE

    End If

    If (HitCount = 3) AND Mute1.Enabled = FALSE AND Mute2.Enabled = FALSE Then
        TestLight3.State = BulbOn
        PlaySound "vo_Help3"
    End If

    If (Hitcount = 4) Then
        TestLight4.State = BulbOn
        HitCount = 0
    End If


    Select Case(fpEventID)
        Case 1: DropLight1.state = BulbOn
        Case 2: DropLight2.state = BulbOn
        Case 3: DropLight3.state = BulbOn
        Case 4: DropLight4.state = BulbOn
    End Select

    If(BanTarget1.dropped = TRUE) Then
        AddScore(5000)
        DTTimer1.Enabled = TRUE
        DTTimer2.Enabled = TRUE
    else
        AddScore(500)
    End If

End Sub

Okay, so... The idea is that every time the bank of drop targets is hit, one of the test lights comes on to tell me that the HitCount is rising. Also, unless a sound is already playing (hence the mute timers), it'll play the next sound in the list. So far so good---

 

EXCEPT for some reason, I never see any test light, other than the first one, light up, thus telling me that the HitCount is not adding anything past 1.

 

How can I fix this?


Edited by SpectreRose, 27 April 2015 - 07:32 AM.


#6 allknowing2012

allknowing2012

    Pinball Fan

  • Members
  • PipPipPipPip
  • 1,948 posts
  • Location:Waterloo, ON

  • Flag: Canada

  • Favorite Pinball: bucaneer

Contributor

Posted 27 April 2015 - 11:32 AM

Not certain about FP vs VP but 

Sub DropTarget1_hit()

 

that would only be called for the 1 target object- was that the intent?


* I don't know everything - I just have no life *
testimageNL

 

 

 

#7 SpectreRose

SpectreRose

    Hobbyist

  • Members
  • PipPip
  • 28 posts

  • Flag: ---------

  • Favorite Pinball: I love too many I can't decide!

Posted 27 April 2015 - 06:37 PM

The DropTarget1_Hit Subroutine tells Future Pinball what to do when any of the four drop targets in that bank has been hit. That part works fine. I have specific lights assigned to each target, and every one of them turns on when their respective target is hit. That part of the script is here:

 Select Case(fpEventID)
        Case 1: DropLight1.state = BulbOn
        Case 2: DropLight2.state = BulbOn
        Case 3: DropLight3.state = BulbOn
        Case 4: DropLight4.state = BulbOn
    End Select

So, even though the Subroutine appears to be marked for one specific target, in reality, the entire Bank of targets is the object here.



#8 allknowing2012

allknowing2012

    Pinball Fan

  • Members
  • PipPipPipPip
  • 1,948 posts
  • Location:Waterloo, ON

  • Flag: Canada

  • Favorite Pinball: bucaneer

Contributor

Posted 27 April 2015 - 06:47 PM

And hitcount is initialized to 0 at the start of the ball/game etc?

Can you add something like 

 

msgbox "Hitcount is " & hitcount

?


* I don't know everything - I just have no life *
testimageNL

 

 

 

#9 SpectreRose

SpectreRose

    Hobbyist

  • Members
  • PipPip
  • 28 posts

  • Flag: ---------

  • Favorite Pinball: I love too many I can't decide!

Posted 27 April 2015 - 08:44 PM

The variable HitCount is a local variable specific to this particular subroutine, thus it won't be initialized at game start, but when the Subroutine is called for the first time. (I have several banks of drop targets that would each have their own HitCount). I've been trying to follow the explanations and script examples provided in Big Draco's scripting guide. There's a section near the top of the page explaining Local Variables. Future Pinball executes scripts on the fly, which is why if something doesn't work right, it won't necessarily crash unless there's something critically wrong with the script at the moment it gets called.

 

From my understanding of the program, when I create a variable (Dim HitCount), then by default it is set at 0 unless I force some other kind of change, such as the following line, "HitCount (which by default is zero) = Hitcount + 1". That value is stored for later use, such as subsequent hits on the bank of Drop Targets. Therefore, every time my bank of drop targets gets hit, the HitCount will increase by 1..... or that's the theory anyway.

 

Regarding your proposal to try a "Hitcount Is" & Hitcount, it seems that all I get are Syntax errors.