Jump to content



Photo
- - - - -

Sleep function?


  • Please log in to reply
16 replies to this topic

#1 DorkmasterFlek

DorkmasterFlek

    Neophyte

  • Members
  • Pip
  • 4 posts

  • Flag: Canada

  • Favorite Pinball: The Twilight Zone

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. smile.gif 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?

#2 Wizards_Hat

Wizards_Hat

    Pinball Fan

  • VP Dev Team
  • PipPipPipPip
  • 1,258 posts
  • Location:Manchester, UK

  • Flag: United Kingdom

  • Favorite Pinball: STTNG




  • Trophies:

Posted 31 May 2011 - 01:13 PM

Hi & welcome to the forums.

A sleep delay would be a really useful tool - don't personally know of one, and can't recall ever having seen one in VP.

Regards,
Dan.
A wizard only needs one ball...but can handle six.

#3 destruk

destruk

    VPF Veteran

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

  • Flag: United States of America

  • Favorite Pinball: Ultrapin!



Posted 31 May 2011 - 05:34 PM

You can load WScript with CreateObject.

Dim WSh
Set WSh=CreateObject("WScript.Shell")

Sleep doesn't seem to work though.

Edited by destruk, 31 May 2011 - 05:37 PM.

Build a fire, vipers love the heat.


#4 DorkmasterFlek

DorkmasterFlek

    Neophyte

  • Members
  • Pip
  • 4 posts

  • Flag: Canada

  • Favorite Pinball: The Twilight Zone

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. smile.gif 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 destruk

destruk

    VPF Veteran

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

  • Flag: United States of America

  • Favorite Pinball: Ultrapin!



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. smile.gif 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.


#6 DorkmasterFlek

DorkmasterFlek

    Neophyte

  • Members
  • Pip
  • 4 posts

  • Flag: Canada

  • Favorite Pinball: The Twilight Zone

Posted 31 May 2011 - 06:59 PM

Oh that's right, I totally forgot VP is open source now. It wasn't several years ago when I last looked at it, I think during the VP6.1 days. smile.gif I'll go digging and see if I can find anything. Thanks!

#7 Greywolf

Greywolf

    Perfectionist Bastard

  • VIP
  • 416 posts
  • Location:West Hyperspace, CA

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

  • Favorite Pinball: Too many to mention



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.


#8 FDSystems

FDSystems

    Eclectic end-user

  • Charter Member
  • 2,477 posts
  • Location:Bahia

  • Flag: Brazil

  • Favorite Pinball: I will have to find out again.............

Posted 01 June 2011 - 01:52 AM

All the above is almost like Chinese to me, but welcome back!
From Brasil. Updated version of 1234fd



#9 DorkmasterFlek

DorkmasterFlek

    Neophyte

  • Members
  • Pip
  • 4 posts

  • Flag: Canada

  • Favorite Pinball: The Twilight Zone

Posted 01 June 2011 - 10:54 AM

Thanks. smile.gif 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 s1500

s1500

    Enthusiast

  • Members
  • PipPipPip
  • 396 posts
  • Location:twin cities

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

  • Favorite Pinball: Fun House

Posted 03 August 2011 - 08:06 PM

QUOTE (DorkmasterFlek @ Jun 1 2011, 05:54 AM) <{POST_SNAPBACK}>
Thanks. smile.gif 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..

#11 destruk

destruk

    VPF Veteran

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

  • Flag: United States of America

  • Favorite Pinball: Ultrapin!



Posted 03 August 2011 - 08:10 PM

Almost every object in VP has its own timer. And you can have an unlimited number of timer objects.

Build a fire, vipers love the heat.


#12 faralos

faralos

    VPF Veteran

  • Members
  • PipPipPipPipPipPip
  • 7,838 posts
  • Location:Eastern Pa,USA

  • Flag: United States of America

  • Favorite Pinball: Flash (Williams) 1979, Flash2 Updated




  • Trophies:

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! whistle.gif biggrin.gif
"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


#13 gStAv

gStAv

    Pinball Lover

  • Members
  • PipPipPipPip
  • 1,331 posts

  • Flag: Sweden

  • Favorite Pinball: TOM, IJ, AFM, WC94

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. angry.gif

Thanks for any help. ('n sorry for me suckin' in vb)

Regards

3rs054-6.png


#14 rosve

rosve

    :)

  • VIP
  • 1,179 posts
  • Location:Always travelling around the world

  • Flag: Sweden

  • Favorite Pinball: Funhouse, Faces, Starship Troopers



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. angry.gif

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


You must add a timer named LWTimer to the table for this to work.

#15 gStAv

gStAv

    Pinball Lover

  • Members
  • PipPipPipPip
  • 1,331 posts

  • Flag: Sweden

  • Favorite Pinball: TOM, IJ, AFM, WC94

Posted 12 January 2012 - 10:46 PM

Thanks a million Roger! cool.gif

Worked right away! biggrin.gif
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. whistle.gif *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

3rs054-6.png


#16 rosve

rosve

    :)

  • VIP
  • 1,179 posts
  • Location:Always travelling around the world

  • Flag: Sweden

  • Favorite Pinball: Funhouse, Faces, Starship Troopers



Posted 12 January 2012 - 10:55 PM

QUOTE (gStAv @ Jan 12 2012, 11:46 PM) <{POST_SNAPBACK}>
Thanks a million Roger! cool.gif

Worked right away! biggrin.gif
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. whistle.gif *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


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 rosve

rosve

    :)

  • VIP
  • 1,179 posts
  • Location:Always travelling around the world

  • Flag: Sweden

  • Favorite Pinball: Funhouse, Faces, Starship Troopers



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.





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
'****************************************************************************
*
'****************************************************************************
*
'****************************************************************************
*