- View New Content
-
Getting Started
-
Tutorials
Tutorial Categories
Tutorials Main Page Installation and Setup Downloadable TutorialsROM Adjustments
Number of Balls Adjustments Volume Adjustments
-
Visual Pinball Tables
VP 8 Desktop Tables
All VPM Recreations VP Recreations VP/VPM MODs VP Originals ROMsVP 9 Desktop Tables
All VPM Recreations VP Recreations VP/VPM MODs VP Originals ROMsVP9 Cabinet Tables
All Full Screen Cabinet Full Screen B2S Cabinet Spanned Cabinet Tables Media Packs ROMsVPX Tables
All VPinMAME Recreations VPX- - /VPinMAME - MOD Tables VPX Recreations VPX Originals Media Packs ROMs VR
-
Frontend Media & Backglass
Media Packs
Complete Media Packs Wheel Logos VideosBackglasses
dB2S Animated Backglasses UVP Animated Backglasses Topper Images
- Future Pinball Tables
-
Design Resources
Main Resources
Table Templates Playfield Images Image Library Sound Library Key CodesVP Guides
VP8 Guide - English VP8 Guide - Deutsch VP9 Guide - English VP9.1.x Guide - English VP Object Guide VPM DocumentationFuture Pinball Resources
Playfield Images 3D Model LibraryFuture Pinball Guides
FP Script Guide Big Draco Script Guide FP Table Design Guide FP DMD Guide
- Other Features
- Bug Tracker
- Image Gallery
- Blogs
-
More
Sleep function?
Started By
DorkmasterFlek
, May 31 2011 01:05 PM
16 replies to this topic
#1
Posted 31 May 2011 - 01:05 PM
First off, hi everybody! I used to mess around with Visual Pinball when I discovered it several years ago, but I haven't looked at it again until now with VP9. This time, instead of just lurking around and playing recreations of my favourite real tables with PinMAME, I decided to try my hand at creating a table myself. The actual table building is the tricky part for me. I'm a software developer by trade (though not with VB), so the scripting doesn't bother me at all.
That having been said, I'm trying to figure out if there's a good simple way to have a basic sleep delay during a subroutine call. Some quick Googling on VBScript turned up the WScript.Sleep function, however this doesn't appear to be available within VP because it doesn't know what "WScript" is (some kind of common VBScript module I presume). I can do it using a timer, but that just strikes me as really clunky, and I can't find anything related to this searching the forums. Surely there must be something I'm overlooking here?
#4
Posted 31 May 2011 - 06:14 PM
Blast, I was afraid of that. You'd think we would have such a basic programming feature included in VP.
That CreateObject call is interesting though, because that is normally called by "WScript.CreateObject". I think perhaps VP is import certain functions from WScript into the global namespace but not others? If that's the case, it should be trivial to include the Sleep function.
#5
Posted 31 May 2011 - 06:26 PM
QUOTE (DorkmasterFlek @ May 31 2011, 12:14 PM) <{POST_SNAPBACK}>
Blast, I was afraid of that. You'd think we would have such a basic programming feature included in VP.
That CreateObject call is interesting though, because that is normally called by "WScript.CreateObject". I think perhaps VP is import certain functions from WScript into the global namespace but not others? If that's the case, it should be trivial to include the Sleep function.
I don't think VP is complex enough to pick and choose methods on external dlls to block - source code is here: vpinball.sourceforge.net
Build a fire, vipers love the heat.
#7
Posted 31 May 2011 - 08:23 PM
Yeah, there is no "sleep". not sure what you're looking to achieve, but I discovered the hard way 9 years ago that there is no sleep -- it's an event-driven script. if you want delays, you have to put in a lock variable that EVERY subroutine acknowledges and exits if it's set so that nothing happens, and then attach a timer routine which will modify that variable. Obviously, do not put the lock test in the timer_expired() routine.
You can't spin-lock in VB(s) or else the script will lock up because it's a continuous state engine with no way to really sleep built in.
You can't spin-lock in VB(s) or else the script will lock up because it's a continuous state engine with no way to really sleep built in.
--*greywolf;
Random Spherical Collisions
Random Spherical Collisions
#9
Posted 01 June 2011 - 10:54 AM
Thanks.
Basically, I want some delay between updating the score on a shot, playing some sound clip, and say kicking the ball back out. You know like, "Play this sound, then wait 2 seconds for effect, then update the score and kick the ball". The lack of sleep makes sense if it's purely event driven and you can't lock up the machine. I guess the best way to handle this is probably a timer for any shots that need this with a state variable that increments each time through. The timer function can go through the needed step each time and increment the state, then set the timer interval accordingly for when the next "step" should happen.
#10
Posted 03 August 2011 - 08:06 PM
QUOTE (DorkmasterFlek @ Jun 1 2011, 05:54 AM) <{POST_SNAPBACK}>
Thanks.
Basically, I want some delay between updating the score on a shot, playing some sound clip, and say kicking the ball back out. You know like, "Play this sound, then wait 2 seconds for effect, then update the score and kick the ball". The lack of sleep makes sense if it's purely event driven and you can't lock up the machine. I guess the best way to handle this is probably a timer for any shots that need this with a state variable that increments each time through. The timer function can go through the needed step each time and increment the state, then set the timer interval accordingly for when the next "step" should happen.
That's what stumped me too. No "wait" function like I use all the time in automation.
I noticed on the great Spiderman pin that there's only 6 or so timers for the whole setup. Does he just run through one timer(say, a timer of 100) x amount of times to get a total wait of 600? That way, you don't have a hundred or so timer objects to mess around with? I saw for loops that decrement from a fixed value that say "timer" somewhere.
I'm going to need quite a few timers just for message delays on the score text. Hmm..
#12
Posted 03 August 2011 - 08:27 PM
so a timer coded with a case select should do it
all that greek stuff is beyond me
( sleep timers) I call 'em alarm clocks!
all that greek stuff is beyond me
( sleep timers) I call 'em alarm clocks!
"Don’t let the noise of others’ opinions drown out your own inner voice.
And most important, have the courage to follow your heart and intuition.”
----Steve Jobs
And most important, have the courage to follow your heart and intuition.”
----Steve Jobs
#13
Posted 12 January 2012 - 09:57 PM
Maybe I can hijack this thread a bit as my concern is almost spot on.
I have this code:
I need a wait loop / timer before de-activate the output stated.
Sub Ledwiz_Activate (LEDWiz_Output, wait_timer)
LedControl.Command = LEDWiz_Output & LEDWiz_On' Turn the output on
I NEED A TIMER FUNCTION LIKE FOR/WHILE OR SOMETHING HERE FOR THE TRIGGERED FLASHER, LIKE 2 SEC. COMES FROM 'wait_timer'
LedControl.Command = LEDWiz_Output & LEDWiz_Off 'Turn the output off
End Sub
Ledwiz_Activate LEDWiz_Start, 2000 'call sub
It all works as for turning the output on/off, but it happends so fast you almost can not see it happend.
Thanks for any help. ('n sorry for me suckin' in vb)
Regards
I have this code:
I need a wait loop / timer before de-activate the output stated.
Sub Ledwiz_Activate (LEDWiz_Output, wait_timer)
LedControl.Command = LEDWiz_Output & LEDWiz_On' Turn the output on
I NEED A TIMER FUNCTION LIKE FOR/WHILE OR SOMETHING HERE FOR THE TRIGGERED FLASHER, LIKE 2 SEC. COMES FROM 'wait_timer'
LedControl.Command = LEDWiz_Output & LEDWiz_Off 'Turn the output off
End Sub
Ledwiz_Activate LEDWiz_Start, 2000 'call sub
It all works as for turning the output on/off, but it happends so fast you almost can not see it happend.
Thanks for any help. ('n sorry for me suckin' in vb)
Regards
#14
Posted 12 January 2012 - 10:18 PM
QUOTE (gStAv @ Jan 12 2012, 10:57 PM) <{POST_SNAPBACK}>
Maybe I can hijack this thread a bit as my concern is almost spot on.
I have this code:
I need a wait loop / timer before de-activate the output stated.
Sub Ledwiz_Activate (LEDWiz_Output, wait_timer)
LedControl.Command = LEDWiz_Output & LEDWiz_On' Turn the output on
I NEED A TIMER FUNCTION LIKE FOR/WHILE OR SOMETHING HERE FOR THE TRIGGERED FLASHER, LIKE 2 SEC. COMES FROM 'wait_timer'
LedControl.Command = LEDWiz_Output & LEDWiz_Off 'Turn the output off
End Sub
Ledwiz_Activate LEDWiz_Start, 2000 'call sub
It all works as for turning the output on/off, but it happends so fast you almost can not see it happend.
Thanks for any help. ('n sorry for me suckin' in vb)
Regards
I have this code:
I need a wait loop / timer before de-activate the output stated.
Sub Ledwiz_Activate (LEDWiz_Output, wait_timer)
LedControl.Command = LEDWiz_Output & LEDWiz_On' Turn the output on
I NEED A TIMER FUNCTION LIKE FOR/WHILE OR SOMETHING HERE FOR THE TRIGGERED FLASHER, LIKE 2 SEC. COMES FROM 'wait_timer'
LedControl.Command = LEDWiz_Output & LEDWiz_Off 'Turn the output off
End Sub
Ledwiz_Activate LEDWiz_Start, 2000 'call sub
It all works as for turning the output on/off, but it happends so fast you almost can not see it happend.
Thanks for any help. ('n sorry for me suckin' in vb)
Regards
This should work,
CODE
Sub Ledwiz_Activate (LEDWiz_Output, wait_timer)
LedControl.Command = LEDWiz_Output & LEDWiz_On' Turn the output on
'Set delay
LWTimer.UserValue = LEDWiz_Output
LWTimer.Interval =wait_timer
LWTimer.Enabled = True
End Sub
Sub LWTimer_Timer()
LWTimer.Enabled = False
LedControl.Command = LWTimer.UserValue & LEDWiz_Off 'Turn the output off
End Sub
LedControl.Command = LEDWiz_Output & LEDWiz_On' Turn the output on
'Set delay
LWTimer.UserValue = LEDWiz_Output
LWTimer.Interval =wait_timer
LWTimer.Enabled = True
End Sub
Sub LWTimer_Timer()
LWTimer.Enabled = False
LedControl.Command = LWTimer.UserValue & LEDWiz_Off 'Turn the output off
End Sub
You must add a timer named LWTimer to the table for this to work.
#15
Posted 12 January 2012 - 10:46 PM
Thanks a million Roger!
Worked right away!
Too bad I can't use the same timer for all called outputs.
Like if I do call them like this
Ledwiz_Activate LEDWiz_Start, 1000
Ledwiz_Activate LEDWiz_Launch, 2000
Ledwiz_Activate LEDWiz_Buyin, 3000
Only the last called command get to use the timer and stuck the rest of the Start and Lauch in ON state.
Hade my hope that it would create like one objekttimer for each sub call.
*lazy me!*
Any better way to solve this other than to use one timer per output?
Would be ok though as it "only" would be like 14 of them otherwise!
Tackar mäster!
/Gustav
Worked right away!
Too bad I can't use the same timer for all called outputs.
Like if I do call them like this
Ledwiz_Activate LEDWiz_Start, 1000
Ledwiz_Activate LEDWiz_Launch, 2000
Ledwiz_Activate LEDWiz_Buyin, 3000
Only the last called command get to use the timer and stuck the rest of the Start and Lauch in ON state.
Hade my hope that it would create like one objekttimer for each sub call.
Any better way to solve this other than to use one timer per output?
Would be ok though as it "only" would be like 14 of them otherwise!
Tackar mäster!
/Gustav
#16
Posted 12 January 2012 - 10:55 PM
QUOTE (gStAv @ Jan 12 2012, 11:46 PM) <{POST_SNAPBACK}>
Thanks a million Roger!
Worked right away!
Too bad I can't use the same timer for all called outputs.
Like if I do call them like this
Ledwiz_Activate LEDWiz_Start, 1000
Ledwiz_Activate LEDWiz_Launch, 2000
Ledwiz_Activate LEDWiz_Buyin, 3000
Only the last called command get to use the timer and stuck the rest of the Start and Lauch in ON state.
Hade my hope that it would create like one objekttimer for each sub call.
*lazy me!*
Any better way to solve this other than to use one timer per output?
Would be ok though as it "only" would be like 14 of them otherwise!
Tackar mäster!
/Gustav
Worked right away!
Too bad I can't use the same timer for all called outputs.
Like if I do call them like this
Ledwiz_Activate LEDWiz_Start, 1000
Ledwiz_Activate LEDWiz_Launch, 2000
Ledwiz_Activate LEDWiz_Buyin, 3000
Only the last called command get to use the timer and stuck the rest of the Start and Lauch in ON state.
Hade my hope that it would create like one objekttimer for each sub call.
Any better way to solve this other than to use one timer per output?
Would be ok though as it "only" would be like 14 of them otherwise!
Tackar mäster!
/Gustav
I must go to sleep now but tomorrow i can make you a better solution that can handle all your outputs with one timer.
#17
Posted 13 January 2012 - 09:43 AM
Here is better way to control the LEDWIZ outputs from the script.
It is a modification of my Fading Lights code.
- Add a timer named LedWTimer. Enable it and set the interval to 33
- Copy the code below to your table.
You will now have two instructions to control the LedWiz outputs, LedWSet and LedWFlash.
SYNTAX
------------------------------------------------------------------------------
LedWSet Output1, Output2, State
Examples:
Set output 3 ON --> LedWSet 3,3,1
Set output 1 to 3 ON --> LedWSet 1,3,1
Set output 3 to 4 OFF --> LedWSet 3,4,0
LedWFlash Output1, Output2, Repeats, On Duration, Off Duration
Examples:
Flash output 2 one time, on for 500 ms --> LedWFlash 2,2,0,500,0
Flash output 2 to 4 four times, on for 100 ms, off for 250 ms --> LedWFlash 2,4,4,100,250
If the number of repeats is set to 999, the output will continue to flash until it is stopped.
It is a modification of my Fading Lights code.
- Add a timer named LedWTimer. Enable it and set the interval to 33
- Copy the code below to your table.
You will now have two instructions to control the LedWiz outputs, LedWSet and LedWFlash.
SYNTAX
------------------------------------------------------------------------------
LedWSet Output1, Output2, State
Examples:
Set output 3 ON --> LedWSet 3,3,1
Set output 1 to 3 ON --> LedWSet 1,3,1
Set output 3 to 4 OFF --> LedWSet 3,4,0
LedWFlash Output1, Output2, Repeats, On Duration, Off Duration
Examples:
Flash output 2 one time, on for 500 ms --> LedWFlash 2,2,0,500,0
Flash output 2 to 4 four times, on for 100 ms, off for 250 ms --> LedWFlash 2,4,4,100,250
If the number of repeats is set to 999, the output will continue to flash until it is stopped.
CODE
'****************************************************************************
***
'****************************** LEDWIZ TOOLBOX ****************************
'*************************** ROSVE 13 JAN 2012 *************************
'****************************************************************************
***
' LedWiz Toolbox Commands
' ------------------------------------------------------------------------------
' LedWSet Output1, Output2, State
' Set output 3 ON --> LedWSet 3,3,1
' Set output 1 to 3 ON --> LedWSet 1,3,1
' Set output 3 to 4 OFF --> LedWSet 3,4,0
'LedWFlash Output1, Output2, Repeats, On Duration, Off Duration
' Flash output 2 one time, on for 500 ms --> LedWFlash 2,2,0,500,0
' Flash output 2 to 4 four times, on for 100 ms, off for 250 ms --> LedWFlash 2,4,4,100,250
' If the number of repeats is set to 999, the output will continue to flash until it is stopped.
Dim LedWmem (32,7)
Sub LedWSet (ByVal OPstart, Byval OPend, Byval State)
Dim lwi
For lwi=OPstart To OPend
LedWmem(lwi,1)=State
LedWmem(lwi,2)=0
Next
End Sub
Sub LedWFlash (ByVal OPstart, Byval OPend, Byval Repeats, Byval OnDur, ByVal OffDur)
Dim lwi
For lwi=OPstart To OPend
LedWmem(lwi,1)=1
LedWmem(lwi,2)=Repeats
LedWmem(lwi,3)=Int(OnDur/33)
LedWmem(lwi,4)=Int(OffDur/33)
LedWmem(lwi,6)=Int(OnDur/33)
LedWmem(lwi,7)=Int(OffDur/33)
Next
End Sub
Sub LedWTimer_Timer()
Dim lwi
For lwi=0 To 32
If LedWmem(lwi,1) <> LedWmem(lwi,5) Then
LedWmem(lwi,5) = LedWmem(lwi,1)
If LedWmem(lwi,1) = 0 Then
LedControl.Command = LedWmem(lwi,1) & LEDWiz_Off' Turn the output off
Else
LedControl.Command = LedWmem(lwi,1) & LEDWiz_On' Turn the output on
End If
End If
IF LedWmem(lwi,2)>0 Then
If LedWmem(lwi,1) = 0 Then
LedWmem(lwi,4)=LedWmem(lwi,4)-1
IF LedWmem(lwi,4) < 1 Then
LedWmem(lwi,1)=Int(Abs(LedWmem(lwi,1)-1))
LedWmem(lwi,4)=LedWmem(lwi,7)
End If
Else
LedWmem(lwi,3)=LedWmem(lwi,3)-1
IF LedWmem(lwi,3) < 1 Then
LedWmem(lwi,1)=Int(Abs(LedWmem(lwi,1)-1))
LedWmem(lwi,3)=LedWmem(lwi,6)
If LedWmem(lwi,2)<999 Then LedWmem(lwi,2)=LedWmem(lwi,2)-1
End If
End If
End If
Next
End Sub
'****************************************************************************
*
'****************************************************************************
*
'****************************************************************************
*
***
'****************************** LEDWIZ TOOLBOX ****************************
'*************************** ROSVE 13 JAN 2012 *************************
'****************************************************************************
***
' LedWiz Toolbox Commands
' ------------------------------------------------------------------------------
' LedWSet Output1, Output2, State
' Set output 3 ON --> LedWSet 3,3,1
' Set output 1 to 3 ON --> LedWSet 1,3,1
' Set output 3 to 4 OFF --> LedWSet 3,4,0
'LedWFlash Output1, Output2, Repeats, On Duration, Off Duration
' Flash output 2 one time, on for 500 ms --> LedWFlash 2,2,0,500,0
' Flash output 2 to 4 four times, on for 100 ms, off for 250 ms --> LedWFlash 2,4,4,100,250
' If the number of repeats is set to 999, the output will continue to flash until it is stopped.
Dim LedWmem (32,7)
Sub LedWSet (ByVal OPstart, Byval OPend, Byval State)
Dim lwi
For lwi=OPstart To OPend
LedWmem(lwi,1)=State
LedWmem(lwi,2)=0
Next
End Sub
Sub LedWFlash (ByVal OPstart, Byval OPend, Byval Repeats, Byval OnDur, ByVal OffDur)
Dim lwi
For lwi=OPstart To OPend
LedWmem(lwi,1)=1
LedWmem(lwi,2)=Repeats
LedWmem(lwi,3)=Int(OnDur/33)
LedWmem(lwi,4)=Int(OffDur/33)
LedWmem(lwi,6)=Int(OnDur/33)
LedWmem(lwi,7)=Int(OffDur/33)
Next
End Sub
Sub LedWTimer_Timer()
Dim lwi
For lwi=0 To 32
If LedWmem(lwi,1) <> LedWmem(lwi,5) Then
LedWmem(lwi,5) = LedWmem(lwi,1)
If LedWmem(lwi,1) = 0 Then
LedControl.Command = LedWmem(lwi,1) & LEDWiz_Off' Turn the output off
Else
LedControl.Command = LedWmem(lwi,1) & LEDWiz_On' Turn the output on
End If
End If
IF LedWmem(lwi,2)>0 Then
If LedWmem(lwi,1) = 0 Then
LedWmem(lwi,4)=LedWmem(lwi,4)-1
IF LedWmem(lwi,4) < 1 Then
LedWmem(lwi,1)=Int(Abs(LedWmem(lwi,1)-1))
LedWmem(lwi,4)=LedWmem(lwi,7)
End If
Else
LedWmem(lwi,3)=LedWmem(lwi,3)-1
IF LedWmem(lwi,3) < 1 Then
LedWmem(lwi,1)=Int(Abs(LedWmem(lwi,1)-1))
LedWmem(lwi,3)=LedWmem(lwi,6)
If LedWmem(lwi,2)<999 Then LedWmem(lwi,2)=LedWmem(lwi,2)-1
End If
End If
End If
Next
End Sub
'****************************************************************************
*
'****************************************************************************
*
'****************************************************************************
*



Top
















are all trademarks of VPFORUMS.