PDA

View Full Version : Play sound effect and turn on object for 1 second' simultaneously



albino_pygmy
04-24-2016, 01:35 PM
So, I've been modifying a game template for some time, and working on my 3 strikes system. This is what a portion of my timer button code looks like, and it works flawlessly.



Sub Timer05()
Dim s As Long
Dim i As Long
Dim t As Long
s = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
'c is a variable already set to Long, and is what triggers where to go in the code when you click on cancel/stop timer

c = 0

For i = 5 To 0 Step -1
ActivePresentation.Slides(s).Shapes("TimerText").TextFrame.TextRange.Text = i
If i = 0 Then
ActivePresentation.Slides(s).Shapes("StrikeFX").ActionSettings(ppMouseClick).SoundEffect.Play
'strikes is a variable set to Long, keeps track of amount of strikes.
If strikes = 3 Then

strikes = 4
End If
'When timer hits zero, this code kicks in, plays sound effect, and then makes visible the appropriate shape for 1 second.

If strikes = 2 Then
t = Timer + 1
ActivePresentation.Slides(s).Shapes("X3").Visible = True
Do Until Timer > t
ActivePresentation.Slides(s).Shapes("TimerText").Visible = True
DoEvents
Loop
ActivePresentation.Slides(s).Shapes("X3").Visible = False
ActivePresentation.Slides(s).Shapes("Canx3").Visible = True

strikes = 3
End If
If strikes = 1 Then
t = Timer + 1
ActivePresentation.Slides(s).Shapes("X2").Visible = True
Do Until Timer > t
ActivePresentation.Slides(s).Shapes("TimerText").Visible = True
DoEvents
Loop
ActivePresentation.Slides(s).Shapes("X2").Visible = False
ActivePresentation.Slides(s).Shapes("Canx2").Visible = True

strikes = 2
End If
If strikes = 0 Then
t = Timer + 1
ActivePresentation.Slides(s).Shapes("X1").Visible = True
Do Until Timer > t
ActivePresentation.Slides(s).Shapes("TimerText").Visible = True
DoEvents
Loop
ActivePresentation.Slides(s).Shapes("X1").Visible = False
ActivePresentation.Slides(s).Shapes("Canx1").Visible = True
strikes = 1
End If
If strikes > 3 Then
strikes = 0
End If
End If
t = Timer + 1
Do Until Timer > t
ActivePresentation.Slides(s).Shapes("TimerText").Visible = True
DoEvents
Loop
If c = 1 Then
i = 0
ActivePresentation.Slides(s).Shapes("TimerText").TextFrame.TextRange.Text = 5
End If
Next
End Sub


So, I originally tried to split up the code into different subs for each of the separate buttons. When a button is clicked (strike1button, strike2button, etc) then I originally wanted this code block to make the same effect of play the sound effect, and then temporarily make the visual strikes (X1, X2, X3) visible for 1 second and then disappear.



'When strike1button gets clicked
sub strike1()
If strikes = 0 Then
t = Timer + 1
ActivePresentation.Slides(s).Shapes("X1").Visible = True
Do Until Timer > t
ActivePresentation.Slides(s).Shapes("TimerText").Visible = True
DoEvents
Loop
ActivePresentation.Slides(s).Shapes("X1").Visible = False
ActivePresentation.Slides(s).Shapes("Canx1").Visible = True
strikes = 1
End If
If strikes > 3 Then
strikes = 0
End If
End If
t = Timer + 1
Do Until Timer > t
ActivePresentation.Slides(s).Shapes("TimerText").Visible = True
DoEvents
Loop
End Sub


Now, unfortunately, things aren't working the same as the timer. Sometimes the X will be visible AFTER the sound effect, or not even visible at all. Below is the code I have currently which is still just as finicky.


Sub Strike1()
Dim s As Long
Dim t As Long
s = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
If strikes = 0 Then
ActivePresentation.Slides(s).Shapes("StrikeFX").ActionSettings(ppMouseClick).SoundEffect.Play
t = Timer + 1
ActivePresentation.Slides(s).Shapes("X1").Visible = True
ActivePresentation.Slides(s).Shapes("Canx1").Visible = True
Do Until Timer > t
ActivePresentation.Slides(s).Shapes("X1").Visible = True
DoEvents
Loop
strikes = 1
c = 1
End If
ActivePresentation.Slides(s).Shapes("X1").Visible = False
End Sub


Any ideas?