Jump to content



Photo
- - - - -

VP equivalent of FP's "FlashForMs" command?


  • Please log in to reply
23 replies to this topic

#1 freneticamnesic

freneticamnesic

    A Faint Ghost Through the Raindrops

  • VIP
  • 3,369 posts
  • Location:Portland, OR

  • Flag: United States of America

  • Favorite Pinball: Star Trek, Black Hole, AFM, Fast Draw, Tron, AMH

  • 360 Gamer Tag: sixgunsounddd

Posted 06 September 2016 - 07:08 AM

Is there something equivalent in VP, or a quick script addition to cover this? I'm sure it's been done so I don't want to re-invent it

 

In FP it's: BulbName.FlashForMs ( <Integer> TotalPeriod, <Integer> BlinkInterval, <Enumeration> EndBulbState )

 

Basically setting a self timer, now bulbs have timers but I hate to add a timer sub for each lamp I want to do this to... any ideas?

I could create a sub with it's own timer but then I could only run one light a time, unless there's another clever workaround.

 

Like this:

 

FlashForMs BulbName, 50

 

Sub FlashForMs(bulb,interval)

Controller.Switch(switchno) = True
If Not switch Is Nothing Then
FlashForMs.TimerInterval = interval
FlashForMs.TimerEnabled = True
End If
 
End Sub
 
and then call the bulbname in the timer? eh not great
help!


#2 BorgDog

BorgDog

    We come in peace.. shoot to kill.. shoot to kill.

  • Members
  • PipPipPipPip
  • 1,427 posts
  • Location:Leavenworth, WA

  • Flag: United States of America

  • Favorite Pinball: Alien Star, TNA



Posted 06 September 2016 - 12:49 PM

hmmm sounds like you should put in a vpx beta feature request for a light object BlinkDuration(integer) which by default would be 0 or -1 for blink until shut off, then you could call Light.blinkduration, 50 and it would start it blinking whatever the pattern was currently set as for 50ms. 

 

how to do in the mean time without a timer for each bulb  :unknw:  but i'll be watching



#3 allknowing2012

allknowing2012

    Pinball Fan

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

  • Flag: Canada

  • Favorite Pinball: bucaneer

Contributor

Posted 06 September 2016 - 01:31 PM

Can you even use the Light interval - I mean, it is currently used in many tables to set the rom ID # for the light ... :-(


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

 

 

 

#4 jpsalas

jpsalas

    Grand Schtroumpf

  • VIP
  • 7,300 posts
  • Location:I'm Spanish, but I live in Oslo (Norway)

  • Flag: Norway

  • Favorite Pinball: I like both new and old, but I guess I prefer modern tables with some rules and goals to achieve.



Posted 06 September 2016 - 01:53 PM

To make light effects I always use the Light Sequencer. Mostly because it doesn't reset the light state.

 

 

Can you even use the Light interval - I mean, it is currently used in many tables to set the rom ID # for the light ... :-(

Yes, but that's only for the startup, and mostly old tables.

 

hmmm sounds like you should put in a vpx beta feature request for a light object BlinkDuration(integer) which by default would be 0 or -1 for blink until shut off, then you could call Light.blinkduration, 50 and it would start it blinking whatever the pattern was currently set as for 50ms. 

 

how to do in the mean time without a timer for each bulb  :unknw:  but i'll be watching

That's a nice idea for a request for VPX :)


If you want to check my latest uploads then click on the image below:

 

vp.jpg

 

Next table? A tribute table to Stern's Foo Fighters


#5 allknowing2012

allknowing2012

    Pinball Fan

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

  • Flag: Canada

  • Favorite Pinball: bucaneer

Contributor

Posted 06 September 2016 - 02:38 PM

Will this do the trick? Created a collection, LightTimer, with the lights you want to flash in it and with group event firing..

 

Call the routine with:

 

FlashForMs TestLight, 10, 500

 

 

Sub FlashForMS (FL,MS, Duration)
  FL.state=LightStateBlinking    ' You want it to blink or just steady on?
  FL.blinkinterval=MS
  FL.timerinterval=Duration
  Fl.timerenabled=True
End Sub
 
Sub LightTimer_Timer(idx)
  LightTimer(idx).timerenabled=False
  LightTimer(idx).state=LightStateOff
End Sub

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

 

 

 

#6 gtxjoe

gtxjoe

    VPF Veteran

  • VIP
  • 5,151 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness, AbraCadabra



Contributor

Posted 06 September 2016 - 07:06 PM

I looked at the core.vbs .CreateEvents approach and used that to create the light_timer( ) subs automatically.  So building on allknowings approach...

Sub FlashForMs (MyLight, TotalPeriod, BlinkPeriod, FinalState)
'===================================================================
' FlashForMs will blink light for TotalPeriod(ms) at rate of BlinkPeriod(ms)
' When TotalPeriod done, light will be set to FinalState value where
' Final State values are:   0=Off, 1=On, 2=Return to previous State
'===================================================================
	If FinalState = 2 Then 
		MyLight.UserValue = MyLight.State		'Save current light state
	Else
		MyLight.UserValue = FinalState			'Save desired final state
	End If

	MyLight.State= 2    	
	MyLight.BlinkInterval= BlinkPeriod
	MyLight.TimerInterval= TotalPeriod
	MyLight.TimerEnabled=True

	'Creates the Timer subroutine.  Uncomment the MsgBox line to see the subroutine string it creates
	'MsgBox "Sub " & MyLight.Name & "_Timer : " & MyLight.name & ".State="& MyLight.name & ".UserValue: "& MyLight.name & ".TimerEnabled=False:  End Sub"
	ExecuteGlobal "Sub " & MyLight.Name & "_Timer : " & MyLight.name & ".State="& MyLight.name & ".UserValue: "& MyLight.name & ".TimerEnabled=False:  End Sub"
End Sub

Example usage:

FlashForMs Light1, 3000, 200, 1 'Blink for 3 sec and leave light on
FlashForMs Light2, 4000, 200, 0 'Blink for 4sec and leave light off
FlashForMs Light3, 5000, 200, 2 'Blink for 5 sec and return light to previous state

Edited by gtxjoe, 06 September 2016 - 07:07 PM.


#7 BorgDog

BorgDog

    We come in peace.. shoot to kill.. shoot to kill.

  • Members
  • PipPipPipPip
  • 1,427 posts
  • Location:Leavenworth, WA

  • Flag: United States of America

  • Favorite Pinball: Alien Star, TNA



Posted 06 September 2016 - 08:03 PM

That's pretty cool Joe.  Didn't know you could create subs on the fly. what happens if there is already one running with that light name and it's called again?

 

Now we just need this added into core, which I evidently asked for poorly in the vpx.2 beta thread :(



#8 freneticamnesic

freneticamnesic

    A Faint Ghost Through the Raindrops

  • VIP
  • 3,369 posts
  • Location:Portland, OR

  • Flag: United States of America

  • Favorite Pinball: Star Trek, Black Hole, AFM, Fast Draw, Tron, AMH

  • 360 Gamer Tag: sixgunsounddd

Posted 06 September 2016 - 09:47 PM

Well that's awesome I'll try it out.

My backup plan was light sequencers as JP suggested, I've used them for flashers before but this table has like 30 or 40 lights it does that to, I was trying to avoid creating a light sequencer for every light (also, simplifying an FP to VP conversion with a script would be a huge benefit)

Thanks guys



#9 freneticamnesic

freneticamnesic

    A Faint Ghost Through the Raindrops

  • VIP
  • 3,369 posts
  • Location:Portland, OR

  • Flag: United States of America

  • Favorite Pinball: Star Trek, Black Hole, AFM, Fast Draw, Tron, AMH

  • 360 Gamer Tag: sixgunsounddd

Posted 06 September 2016 - 10:06 PM

That works great gtxjoe and allknowing. Thank you so much.

Anyone know if intervals are equivalent between FP and VPX? I know the values changed between VP9 and VPX, are they near enough that it doesn't make a difference or should I be adding 0s?



#10 jpsalas

jpsalas

    Grand Schtroumpf

  • VIP
  • 7,300 posts
  • Location:I'm Spanish, but I live in Oslo (Norway)

  • Flag: Norway

  • Favorite Pinball: I like both new and old, but I guess I prefer modern tables with some rules and goals to achieve.



Posted 07 September 2016 - 04:57 PM

It works very nice! Thanks! On some original tables I added the blinking effect when hitting a target, but I made it quite complicated, that's why I didn't added for ex. to the Pokémon table. So I'll be using a combination of this effect and the light sequencer on my next tables. :) Now I just need to find a way to to the same with the flashers :)


If you want to check my latest uploads then click on the image below:

 

vp.jpg

 

Next table? A tribute table to Stern's Foo Fighters


#11 gtxjoe

gtxjoe

    VPF Veteran

  • VIP
  • 5,151 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness, AbraCadabra



Contributor

Posted 07 September 2016 - 06:19 PM

I assume you mean the actual Flasher object and not simlply a light object used as a flasher.

 

I do have an initial more complicated version of the FlashForMs subroutine that might convert easily for flasher object use.  Send me the flasher subroutines and flashertimer sub approach you are using in VPX and  I can take a look at modifying what I have.



#12 jpsalas

jpsalas

    Grand Schtroumpf

  • VIP
  • 7,300 posts
  • Location:I'm Spanish, but I live in Oslo (Norway)

  • Flag: Norway

  • Favorite Pinball: I like both new and old, but I guess I prefer modern tables with some rules and goals to achieve.



Posted 08 September 2016 - 01:36 AM

The latest flasher routine I'm using for original tables is in the Pokémon table. For vpinmame tables the fading sub works just fine. But for originals I should like to have more freedom since I should like to be able to change the effects on the flashers, fro example I should like to make them flash quickly, and sometimes make them pulse with a slow fade inn and out. I can do that with my sub but not as good as I should like :)


If you want to check my latest uploads then click on the image below:

 

vp.jpg

 

Next table? A tribute table to Stern's Foo Fighters


#13 fuzzel

fuzzel

    spaghetti code

  • VP Dev Team
  • PipPipPipPipPip
  • 2,818 posts

  • Flag: Germany

  • Favorite Pinball: yes I have

Posted 08 September 2016 - 10:51 AM

Just a quick note: VP 10.2 beta rev2778 supports a new command for the lights: "Duration". It can be used when the light is in ON or BLINKING state. If set >0 the light will switch off when the duration time expires. If you set the duration=0 the duration handling is switched off and a light will blink forever or stays on.



#14 freneticamnesic

freneticamnesic

    A Faint Ghost Through the Raindrops

  • VIP
  • 3,369 posts
  • Location:Portland, OR

  • Flag: United States of America

  • Favorite Pinball: Star Trek, Black Hole, AFM, Fast Draw, Tron, AMH

  • 360 Gamer Tag: sixgunsounddd

Posted 08 September 2016 - 04:48 PM

Savage.



#15 gtxjoe

gtxjoe

    VPF Veteran

  • VIP
  • 5,151 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness, AbraCadabra



Contributor

Posted 09 September 2016 - 04:42 PM

Here is an initial version for strobing/blinking Flasher objects for VPX 10.2 only.  It requires the modified JP Flasher fading subroutines so copy and paste JP's Fading routines AND FlasherForMS routine from the attached demo Table

Sub FlasherForMs (FlasherIndex, MyFlasher, TotalPeriod, BlinkPeriod, FinalState)
'===================================================================
' For use with VPX 10.2 or later:  Requires specific version of flasher subroutines
' FlasherForMs will strobe Flasher for TotalPeriod(ms) at rate of BlinkPeriod(ms)
' When TotalPeriod done, flasher will be set to FinalState value where
' Final State values are:   0=Off, 1=On, 2=Return to previous State
'===================================================================
	Dim Fblinks

	' Store all blink information
	Fblinks = Int(TotalPeriod/BlinkPeriod + .5)	'Number of blinks to perform
	If FinalState > 1 And FadingLevel(FlasherIndex) > 0 Then 	'Check if Flasher needs to store current on/off state
		FinalState = 1
	ElseIf FinalState > 1  Then 
		FinalState = 0
	End If
	MyFlasher.UserValue = FBlinks*4096 + FlasherIndex*4 + FinalState	'Store # of blinks, flasher index and final state

	' Start blink timer and create timer subroutine
	MyFlasher.TimerInterval = BlinkPeriod
	MyFlasher.TimerEnabled = 1
	FlashState(FlasherIndex) = 1
	FadingLevel(FlasherIndex) = 1
	ExecuteGlobal "Sub " & MyFlasher.Name & "_Timer:" & "dim tmp,fblinks,fstate,index: tmp=me.UserValue:fblinks=(tmp And &HFFFFF000)/4096-1:index=(tmp And &H3FC)/4:fstate=(tmp And &H3):me.UserValue=fblinks*4096+index*4+fstate:if fblinks>0 then If FadingLevel(index)>0 Then FlashState(index)=0:FadingLevel(index)=0 Else FlashState(index)=1:FadingLevel(index)=1 End If Else FlashState(index)=fstate:FadingLevel(index)=fstate:me.timerenabled=0:End if: End Sub"
End Sub

- This will only work on the VPX 10.2 revision 2778 or later since there was a Flasher object timer fix needed. ( I do have a version that works with 10.1 but it requires a timer for each flasher)

- It requires the flasher index and flasher object used in your FlashTimer_Timer subroutines

- @JPSalas, I had to modify one line of the Sub Flash() routine to get this to work, "FadingLevel(n) = 10 'stopped" .   (I needed the end FadingLevel values for ON state to be a positive number (1 and 10), so I could distinguish it from OFF state(0 or -1)

 

More details on the creation of the required timer subroutine for those interested.  The ExecuteGlobal creates it on the fly.  Here is an example of what it creates:

'Sub Flasherx_Timer
'dim tmp,fblinks, fstate, index
'
'	tmp = me.UserValue 
'	fblinks = (tmp And &HFFFFF000)/4096 - 1
'	index = (tmp And &H3FC) / 4
'	fstate = (tmp And &H3)
'	me.UserValue = fblinks*4096 + index*4 + fstate	'Store # of blinks, flasher index and final state
'
'	if fblinks > 0 then 
'		If FadingLevel(index) > 0 Then 
'			FlashState(index) = 0: FadingLevel(index) = 0
'		Else
'			FlashState(index) = 1: FadingLevel(index) = 1
'		End If
'	Else
'		FlashState(index)=fstate:FadingLevel(index)=fstate
'		me.enabled=0
'	End if
'End Sub

Attached Files


Edited by gtxjoe, 09 September 2016 - 04:51 PM.


#16 jpsalas

jpsalas

    Grand Schtroumpf

  • VIP
  • 7,300 posts
  • Location:I'm Spanish, but I live in Oslo (Norway)

  • Flag: Norway

  • Favorite Pinball: I like both new and old, but I guess I prefer modern tables with some rules and goals to achieve.



Posted 09 September 2016 - 05:02 PM

Thanks gtxjoe! I guess we can remove the blinking part of my routine. It works very fine and it does just what I wanted :D


If you want to check my latest uploads then click on the image below:

 

vp.jpg

 

Next table? A tribute table to Stern's Foo Fighters


#17 freneticamnesic

freneticamnesic

    A Faint Ghost Through the Raindrops

  • VIP
  • 3,369 posts
  • Location:Portland, OR

  • Flag: United States of America

  • Favorite Pinball: Star Trek, Black Hole, AFM, Fast Draw, Tron, AMH

  • 360 Gamer Tag: sixgunsounddd

Posted 09 September 2016 - 05:16 PM

:love39:



#18 jpsalas

jpsalas

    Grand Schtroumpf

  • VIP
  • 7,300 posts
  • Location:I'm Spanish, but I live in Oslo (Norway)

  • Flag: Norway

  • Favorite Pinball: I like both new and old, but I guess I prefer modern tables with some rules and goals to achieve.



Posted 11 September 2016 - 07:24 AM

Hi gtxjoe and everybody!

 

I changed the FlashForms to be used with the latest changes in the lights in VPX 10.2 rev 2781.

I also changed the routine so it can be used for both lights and flashers using the same syntax and Sub.

For the flashers I didn't use my old fading flash routine. It simply uses the Visible property. So there is no need for extra routines nor timers.

If you prefer the flashers fading then use the one gtxjoe made. But for my needs this is a shorter and easier version of FlashForms :)

'********************************************************************************************
' Only for VPX 10.2 and higher.
' FlashForMs will blink light or a flasher for TotalPeriod(ms) at rate of BlinkPeriod(ms)
' When TotalPeriod done, light or flasher will be set to FinalState value where
' Final State values are:   0=Off, 1=On, 2=Return to previous State
'********************************************************************************************

Sub FlashForMs(MyLight, TotalPeriod, BlinkPeriod, FinalState) 'thanks gtxjoe for the first version

    If TypeName(MyLight) = "Light" Then

        If FinalState = 2 Then
            FinalState = MyLight.State                 'Keep the current light state
        End If
        MyLight.State = 2
        MyLight.BlinkInterval = BlinkPeriod
        MyLight.Duration TotalPeriod, FinalState
    ElseIf TypeName(MyLight) = "Flasher" Then

        Dim steps

        ' Store all blink information
        steps = Int(TotalPeriod / BlinkPeriod + .5) 'Number of ON/OFF steps to perform
        If FinalState = 2 Then                        'Keep the current flasher state
            FinalState = ABS(MyLight.Visible)          
        End If
        MyLight.UserValue = steps * 10 + FinalState 'Store # of blinks, and final state

        ' Start blink timer and create timer subroutine
        MyLight.TimerInterval = BlinkPeriod
        MyLight.TimerEnabled = 1
        ExecuteGlobal "Sub " & MyLight.Name & "_Timer:" & "Dim tmp, steps, fstate:tmp=me.UserValue:fstate = tmp MOD 10:steps= tmp\10 -1:Me.Visible = steps MOD 2:me.UserValue = steps *10 + fstate:If Steps = 0 then Me.Visible = fstate:Me.TimerEnabled=0:End if:End Sub"
    End If
End Sub

Here it is a table as example. Simple press the LEFT SHIFT to blink the light, and press the RIGHT SHIFT to blink the flasher.

The syntax used are the same for both the light and the flasher:

For the light: FlashForMs Light1, 2000, 50, 0

and for the flasher: FlashForMs Flasher1, 2000, 50, 0

 

 

Edit: fixed the 2 errors (one logic error and one math error :) )


Edited by jpsalas, 11 September 2016 - 02:28 PM.

If you want to check my latest uploads then click on the image below:

 

vp.jpg

 

Next table? A tribute table to Stern's Foo Fighters


#19 freneticamnesic

freneticamnesic

    A Faint Ghost Through the Raindrops

  • VIP
  • 3,369 posts
  • Location:Portland, OR

  • Flag: United States of America

  • Favorite Pinball: Star Trek, Black Hole, AFM, Fast Draw, Tron, AMH

  • 360 Gamer Tag: sixgunsounddd

Posted 11 September 2016 - 08:29 AM

Strange...JP change the blinkperiod on the flasher to 200 and run it, seems to end with an on state


Using rev 2781



#20 unclewilly

unclewilly

    sofa king.....

  • VIP
  • 5,170 posts
  • Location:Baltimore, Maryland

  • Flag: United States of America

  • Favorite Pinball: tz, tom, big hurt, who dunnit



Posted 11 September 2016 - 11:49 AM

Thanks for this guys. I've been planning a fp to vpx conversion and this will make converting the script much easier.

I wish some of those old fp authors were still around so i could get permission ti release it when I'm done

"it will all be ok in the end, if it's not ok, it's not the end"
 
Monster Bash VP10 WIP https://dl.dropboxus... (vpx)WIP15.vpx

uw2.gif