Author Topic: Rosve's Fading Lights System  (Read 14822 times)

0 Members and 1 Guest are viewing this topic.

Offline rosve

  • Newbie
  • *
  • Posts: 21
  • Karma: +1/-0
Rosve's Fading Lights System
« on: October 20, 2012, 09:04:54 AM »
Here is a demo table and a description on how to use my fading lights code.
This system is specially made to make it easy to create really good looking lights on EM and original tables. It gives you much more control over the lights than the standard VP lights.

I have been using this code in tables like SPACE:1999, Red Dwarf, SkyRocket and many more.

DEMO TABLE DOWNLOAD

MANUAL (also included in the download)

- Add the Fading Lights code to the end of the table script.

- Create a new timer and name it "FLTimer". Set the interval to 33 and Enable it.

- Create a light somewhere besides the table and name it "DummyLight"

- Create 2 new collections, "L1" and "L2". Put the DummyLight in both collections.

- Make 3 playfield images with the   Lights Off,   Lights Halfe On,   Lights Full On.

- Add all the lights needed on the playfield (light1 - 14 on the demo table).
  On all the lights, Set the Off Image to the 'Lights Off' image. Set the On Image to the 'Lights Halfe On' image.

- Enter the lights into the "L1" collection.

- Copy and paste all the lights so that you get two lights in the same position.
  On all the new lights, Set the Off Image to the 'Lights Halfe On' image. Set the On Image to the 'Lights Full On' image.

- Enter the new lights into the "L2" collection.

- set the variable "FLMaxLight" (3rd line in the fading lights code) to the number of lights that you made. 14 in the demo table.


YOU ARE NOW READY TO USE THE FADING LIGHTS.
-------------------------------------------

- Insert this line in the table _Init sub to initialize the fading lights system,
  FLFlash 1, FLMaxLight, 0, 1, 4, 0



Use the following instructions to set a light (or a group of lights) ON, OFF or FLASHING


FLSetOn light1, light2, delay
   - Light number from Light1 to Light 2 is set to ON.
   - If the Delay is larger than 0 the code will wait the specified number of timer intervals before setting the lights ON.


FLSetOff light1, light2, delay
   - Light number from Light1 to Light 2 is set to OFF.
   - If the Delay is larger than 0 the code will wait the specified number of timer intervals before setting the lights OFF.



FLFlash light1, light2, repeats, on_duration, off_duration, delay
   - Light number from Light1 to Light 2 is set to FLASHING.
   - repeats is how many times the lights shall flash, 999 is continous flashing.
   - on_duration and off_duration specifies how many timer intervals the light shall stay on and off in the flashing cycle.
   - If the Delay is larger than 0 the code will wait the specified number of timer intervals before setting the lights to FLASHING.




EXAMPLES
--------

Set light 4 on.
     FLSetOn 4, 4, 0

Set light 3 to 6 on after a small delay,
     FLSetOn 3, 6, 10

Set light 4 off.
     FLSetOff 4, 4, 0

Flash light 6 three times,
     FLFlash 6, 6, 2, 2, 4, 0

Flash all light one time
     FLFlash 1, FLMaxLight, 0, 1, 4, 0

Offline unclewilly

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
RE: Rosve's Fading Lights System
« Reply #1 on: October 20, 2012, 02:44:16 PM »
Very nice.
I appreciate this,  will save a bunch of time on my 2 original projects

Offline Itchigo

  • Victory is mine!!
  • Administrator
  • Pinball Wizard
  • *****
  • Posts: 1,423
  • Country: us
  • Karma: +10/-0
RE: Rosve's Fading Lights System
« Reply #2 on: October 20, 2012, 11:28:08 PM »
Thanks Rosve!
Tremble in fear! Behold my Bankai!


Offline rosve

  • Newbie
  • *
  • Posts: 21
  • Karma: +1/-0
RE: Rosve's Fading Lights System
« Reply #3 on: October 21, 2012, 02:46:03 AM »
Forgot to show how my code can also control the alpha flashers.
NEW DEMO
I made another light (#15) that is connected to a flasher.

Offline unclewilly

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
RE: Rosve's Fading Lights System
« Reply #4 on: October 21, 2012, 06:46:54 AM »
I havent had a chance to look at this yet rosev as ive been working all weekends.
Is it set up in subroutines like jps system so we can do custom light scripts and alpha flashers?

Thanks again for this

Offline rosve

  • Newbie
  • *
  • Posts: 21
  • Karma: +1/-0
RE: Rosve's Fading Lights System
« Reply #5 on: October 21, 2012, 07:07:35 AM »
Quote from: 'unclewilly' pid='58' dateline='1350820014'

I havent had a chance to look at this yet rosev as ive been working all weekends.
Is it set up in subroutines like jps system so we can do custom light scripts and alpha flashers?

Thanks again for this


It's not like JPs system at all, this fading system is much more automated. Every time a light state is changed it makes a call to a sub where you can add any code you want for each light number.
See the new demo in my previous post for an alpha flasher demo.

One major difference compared to the JP script is that I use 3 states only, OFF, PARTLY ON, FULL ON. It looks just as good but reduces the amount of state changes by a 3rd.
I do a lot of these code optimisations in my tables to make them as smooth as possible even on low spec computers :cool:.

Offline unclewilly

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
RE: Rosve's Fading Lights System
« Reply #6 on: October 21, 2012, 07:22:59 AM »
Sorry for all the questions cause i havent had a chance to look at it yet.
You think it could be adapted to work with pinmame as well?

Im working on a demo table also for fading gi lighting

Offline rosve

  • Newbie
  • *
  • Posts: 21
  • Karma: +1/-0
RE: Rosve's Fading Lights System
« Reply #7 on: October 21, 2012, 07:28:35 AM »
Quote from: 'unclewilly' pid='60' dateline='1350822179'

Sorry for all the questions cause i havent had a chance to look at it yet.
You think it could be adapted to work with pinmame as well?

Im working on a demo table also for fading gi lighting


Check out my Starship Troopers table. There I use my fading system with VPM.

Offline unclewilly

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
RE: Rosve's Fading Lights System
« Reply #8 on: October 21, 2012, 08:34:48 PM »
Just had a look at the demo and starship.  Your system works very nice.
Im not sure what it is but when comparing to the standard fading light script with 4 steps yours seems to show the fade much better.
Really looking forward to trying it out.

Offline faralos

  • Full Member
  • ***
  • Posts: 235
  • Karma: +1/-0
RE: Rosve's Fading Lights System
« Reply #9 on: October 24, 2012, 07:19:38 AM »
Here is a question, is it possible to have a lamp light up like one in a lighthouse?
I want a flasher bulb to flash brilliance then fade out slowly like a capacitor does with electricity
like a strobe I guess
I am never wrong Once I thought I was
 but I was merely mistaken

Offline rosve

  • Newbie
  • *
  • Posts: 21
  • Karma: +1/-0
RE: Rosve's Fading Lights System
« Reply #10 on: October 24, 2012, 08:13:28 AM »
Quote from: 'faralos' pid='107' dateline='1351081178'

Here is a question, is it possible to have a lamp light up like one in a lighthouse?
I want a flasher bulb to flash brilliance then fade out slowly like a capacitor does with electricity
like a strobe I guess


Yes, but it will take a little extra coding to do that.

Offline unclewilly

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
RE: Rosve's Fading Lights System
« Reply #11 on: October 24, 2012, 08:26:29 AM »
If its only a single light.  I would just use a timer and a case select statement outside of the fading light script

Offline rosve

  • Newbie
  • *
  • Posts: 21
  • Karma: +1/-0
RE: Rosve's Fading Lights System
« Reply #12 on: October 24, 2012, 09:49:58 AM »
Quote from: 'unclewilly' pid='117' dateline='1351085189'

If its only a single light.  I would just use a timer and a case select statement outside of the fading light script


same here, I would only use my system to activate the timer so that the "lighthouse" is controlled the same way as all other lights in the table script.

Offline unclewilly

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
RE: Rosve's Fading Lights System
« Reply #13 on: October 24, 2012, 02:29:39 PM »
Dumb request.  I dont have access to my pc for a few days.  Could someone copy rosev light script from the demo table into a text editor and upload it.  Id like to be able to look at the script on my phone while im at work.

Still trying to get a grasp on it and make sure i can use it in my badcats update.

In this table i have some fading lights that are also dropwalls and id like to have the alpha flashers fade as well
Just havent had time to work with it so id like to take a look at it.

Thanks for the help

Offline rosve

  • Newbie
  • *
  • Posts: 21
  • Karma: +1/-0
RE: Rosve's Fading Lights System
« Reply #14 on: October 25, 2012, 11:09:53 AM »
OK, here is the script from the demo table.
Code: [Select]

Sub Table1_Init()
   FLFlash 1, FLMaxLight, 0, 1, 4, 0
End Sub


Sub Table1_KeyDown(ByVal keycode)
       FLFlash 1, 1, 10, 1, 32, 0
       FLFlash 2, 2, 10, 1, 32, 4
       FLFlash 3, 3, 10, 1, 32, 8
       FLFlash 4, 4, 10, 1, 32, 12
       FLFlash 5, 6, 10, 1, 32, 16
       FLFlash 7, 8, 10, 1, 32, 20
       FLFlash 9, 10, 10, 1, 32, 24
       FLFlash 11, 12, 10, 1, 32, 28
       FLFlash 13, 14, 10, 1, 32, 32

       'Flasher
       FLFlash 15, 15, 2, 0, 1, 14
End Sub





'*********************************************************************************************
'*****************               FADING LIGHTS CODE                ***************************
'*****************                     ROSVE                       ***************************
'*********************************************************************************************
Dim FLData(100,8)
Dim FLMaxLight
FLMaxLight=15
' 1=command --> 0=set off   1=set on   2=flash   99=no change
' 2=state
' 3=repeats   999=continous
' 4=on duration
' 5=off duration
' 6=on dur mem
' 7=off dur mem
' 8=start delay

Sub FLSetOn(ByVal FLlight1, ByVal FLlight2, ByVal FLdelay)
   For i=FLlight1 to  FLlight2
      FLData(i,1)=1
      FLData(i,2)=0
      FLData(i,3)=0
      FLData(i,4)=0
      FLData(i,5)=0
      FLData(i,8)=FLdelay
   Next
End Sub

Sub FLSetOff(ByVal FLlight1, ByVal FLlight2, ByVal FLdelay)
   For i=FLlight1 to  FLlight2
      FLData(i,1)=0
      FLData(i,2)=4
      FLData(i,3)=0
      FLData(i,4)=0
      FLData(i,5)=0
      FLData(i,8)=FLdelay
   Next
End Sub

Sub FLFlash(ByVal FLlight1, ByVal FLlight2, ByVal FLrepeat, ByVal FLondur, ByVal FLoffdur, ByVal FLdelay)
   For i=FLlight1 to  FLlight2
      FLData(i,1)=2
      FLData(i,2)=0
      FLData(i,3)=FLrepeat
      FLData(i,4)=FLondur
      FLData(i,5)=FLoffdur
      FLData(i,6)=FLondur
      FLData(i,7)=FLoffdur
      FLData(i,8)=FLdelay
   Next
End Sub

Sub FLTimer_Timer()
Dim i
   For i=1 To FLMaxLight
      If FLData(i,8)>0 Then
         FLData(i,8)=FLData(i,8)-1
      Else
         Select Case FLData(i,1)
         Case 0
            FLData(i,2)=FLData(i,2)+1
            Select Case FLData(i,2)
            Case 5
               FLflasher i,1
               L2(i).State=0
            Case 7
               FLflasher i,0
               L1(i).State=0
               FLData(i,1)=99
            End Select
         Case 1
            FLData(i,2)=FLData(i,2)+1
            Select Case FLData(i,2)
            Case 1
               FLflasher i,1
               L1(i).State=1
            Case 3
               FLflasher i,2
               L2(i).State=1
               FLData(i,1)=99
            End Select

         Case 2
            FLData(i,2)=FLData(i,2)+1
            Select Case FLData(i,2)
            Case 1
               FLflasher i,1
               L1(i).State=1
            Case 3
               FLflasher i,2
               L2(i).State=1
            Case 4 'on Duration
               IF FLData(i,4)>0 Then
                  FLData(i,4)=FLData(i,4)-1
                  FLData(i,2)=FLData(i,2)-1
               Else
                  FLData(i,4)=FLData(i,6)
               End If
            Case 5
               FLflasher i,1
               L2(i).State=0
            Case 7
               FLflasher i,0
               L1(i).State=0
               IF FLData(i,3)>0 Then
                   IF FLData(i,5)>0 Then
                      FLData(i,5)=FLData(i,5)-1
                      FLData(i,2)=FLData(i,2)-1
                   Else
                      FLData(i,5)=FLData(i,7)
                      FLData(i,3)=FLData(i,3)-1
                      If FLData(i,3)=998 Then FLData(i,3)=999
                      FLData(i,2)=0
                   End If
               Else
                  FLData(i,1)=99
               End If
            End Select
         End Select
      End If
   Next
End Sub

Sub FLflasher(ByVal li,ByVal st)
   Dim i
   Select Case li  '**** LIGHT NUMBER *****
      Case 15      'Light 15 is an Alpha Flasher
         Select Case st
            Case 0'OFF
               f32f1.alpha = 0
            Case 1'INTERMIDIATE
               f32f1.image =  "rf_b":f32f1.alpha = 1
            Case 2 'ON
               f32f1.image = "rf_on"
         End Select
         f32r1.State=ABS(f32r1.state -1)
   End Select
End Sub
'*********************************************************************************************
'*********************************************************************************************
'*********************************************************************************************






---------------------------------------------------------
To use it with VPM you also need this code snippet to read the lamp states.

Code: [Select]

Dim NewState(200)
Dim OldState(200)

FLTimer.Interval = 21
LampTimer.Interval = 10
LampTimer.Enabled = 1

Sub SetFlasher(nr, value)
   NewState(nr) = abs(value)
End Sub

Sub LampTimer_Timer()
    Dim chgLamp, num, chg, ii
    chgLamp = Controller.ChangedLamps
    If Not IsEmpty(chgLamp) Then
        For ii = 0 To UBound(chgLamp) ' **UPDATE LAMP STATES ***
            If chgLamp(ii, 1)=0 then
               FLSetOff chgLamp(ii, 0), chgLamp(ii, 0), 0
            else
               FLSetOn chgLamp(ii, 0), chgLamp(ii, 0), 0
            end if
        Next
    End If
    For ii=81 to 88 ' ******** FLASHER NUMBERS *************
       If NewState(ii) <> OldState(ii) then
          OldState(ii)=NewState(ii)
          If NewState(ii)=0 then
             FLSetOff ii, ii. 0
          else
             FLSetOn ii, ii, 0
          end if
       end if
    Next
End Sub[/php]


Solenoid controlled flasher states are read like this,
Code: [Select]

SolCallBack(25)="SetFlasher 81, " 'red x 4
SolCallBack(26)="SetFlasher 82, "   'yellow x 4
SolCallBack(27)="SetFlasher 83, " 'green x 4
SolCallBack(28)="SetFlasher 84, " 'blue x 4
SolCallBack(29)="SolWarrior" 'flash multiball x 4
SolCallBack(30)="SetFlasher 86, " 'left ramp x 4
SolCallBack(31)="SetFlasher 87, " 'right ramp x 4
SolCallBack(32)="SetFlasher 88, " 'pops x 2