beautypg.com

Using a table of times for high and low tide – ETC Unison Mosaic Designer v1.11.0 User Manual

Page 224

background image

Unison Mosaic Designer User Manual

This is probably the better solution because it avoids having a script running every second for no reason. There is
some overhead involved in running scripts and it is best to keep the number of scripts that run to the minimum
necessary - particularly if the Controller is heavily loaded doing lighting effects at the same time.

Using a table of times for high and low tide

A Controller is controlling the lighting on a bay bridge. The client wants a lighting effect to run at high tide and
another effect at low tide. The client has provided tide tables for the entire year and plans to update the tables
each year.

A lot of the fun in this situation is in converting the data from the format in which it is provided into a Lua table.
This is usually an exercise in Excel and search and replace tools, which I won't cover here. So let's assume we
have generated a Lua file of the form:

high_tides = {

07,11,08,13,45, -- 13:45, 8 November 2007

07,11,09,00,36, -- 00:36, 9 November 2007

07,11,09,11,21, -- 11:21, 9 November 2007

etc...

}

It's best to put large tables like this in their own separate files and run them as separate scripts on startup. Load-
ing a large table like this into memory will take a noticeable amount of time, so you certainly don't want to do that
more than once. Also if the tide tables are going to be changed each year then keeping them in a separate file min-
imises what has to be changed.

We would then also have a realtime trigger that fires every minute and runs the script:

-- check if our index variable is initialised

if not h then

h = 0

end

-- make sure we don't run off the end of the table

while high_tides[h*5] do

-- compare the current time against table

year = realtime.year

if high_tides[h*5] > year then

-- not yet reached this entry

return

elseif high_tides[h*5] == year then

month = realtime.month

if high_tides[(h*5)+1] > month then

-- not yet reached this entry

return

elseif high_tides[(h*5)+1] == month then

day = realtime.monthday

if high_tides[(h*5)+2] > day then

-- not yet reached this entry

return

elseif high_tides[(h*5)+2] == day then

- 224 -