Advanced conditions allow you to control when an item is displayed using JavaScript-like expressions.
Data defined in the active screen, stack item, slot, or sequence can be used in expressions. This data can be populated by sensors such as GPS, manually set in data fields, or automatically updated by 3rd party services.
The stack item will only display if the expression evaluates to true
.
Remember to test conditions in the admin interface. Press the a=b button on the sequence tab or playback simulator to set the value of variables.
Basic Syntax
There are a variety of predefined variables and helper functions to enable powerful logic to be defined.
Syntax | Description |
---|---|
== |
Test for equality. For example temp == 23 will only return true when the data named temp is set to 23 . |
!= |
Test for inequality. For example temp != 23 will only return true when the data named temp is not set to 23 . |
> |
Test if one value is greater than another. For example temp > 23 will only return true when the data named temp is greater than 23 . |
< |
Test if one value is less than another. For example temp < 23 will only return true when the data named temp is less than 23 . |
>= , <=
|
Syntax for greater than or equal to and less than or equal to. |
&& |
Ensures two expressions are true. For example temp < 23 && screenSize > 40 only returns true when the data named temp is less than 23 and the data named screenSize is greater than 40 . |
|| |
Ensures either expression is true. For example temp < 23 || screenSize > 40 returns true when the data named temp is less than 23 or the data named screenSize is greater than 40 . |
( , )
|
Control grouping and order of evaluation. For example true || (true && false) returns true but (true || true) && false returns false . |
Date and Time Functions
The time zone used by default will be the time zone of the device.
Syntax | Description |
---|---|
time.after("2014-02-01") |
true if time is after 1st Feb midnight. |
time.after("2014-02-01 12:00") |
true if time is after 1st Feb 12pm. |
time.before("2014-02-15 13:00") |
true if time is before 15th Feb 1pm. |
time.hour() == 13 |
true if hour is 1pm. |
time.decimalHour() > 13.5 |
true if time is after 1:30pm (decimal). |
time.after("13:30") |
true if time is after 1:30pm (time). |
time.day() == "Thursday" |
true if day is Thursday. |
time.weekday() |
true if it is a weekday. |
time.weekend() |
true if it is a weekend. |
time.month() == "August" |
true if month is August. |
time.minute() == 5 |
true at 5 minutes past every hour. |
time.second() == 59 |
true at 59 seconds past every minute. |
time.date() == 1 |
true if it is the 1st day of the month. |
time.between("14:05", "16:30") |
true if time is between 2:05pm and 4:40pm. |
time.between("18:00", "07:00") |
true if time is between 6pm and 7am of the following day. |
time.between("2014-01-01", "2014-01-31") |
true if time is between 1st Jan 12am and 31st Jan 12am. |
time.between("2014-01-01 10:00", "2014-01-31 14:00") |
true if time is between 1st Jan 10am and 31st Jan 2pm. |
time.between("19:00", "22:00", "Europe/London") |
Use a custom timezone. - true if time is between 7pm and 10pm in London. (player 11.11+) |
time.millis() |
Milliseconds since the UNIX epoch (January 1, 1970 00:00:00 UTC). |
Geolocation Functions
Syntax | Description |
---|---|
distanceMiles(51.48, -0.10) < 10 |
true if the location of the screen is less than 10 miles from the location with latitude of 51.48 and longitude of -0.10. |
distanceKilometers(51.48, -0.10) < 20 |
true if the location of the screen is less than 20 kilometers from the location with latitude of 51.48 and longitude of -0.10. |
gpsInside(lat1,lng1,lat2,lng2,lat3,lng3...) |
true if the location of the screen is inside the polygon defined by the list of latitude longitude pairs. Please note, this function is designed for short distances (max 100km) that do not cross the international dateline. android-player-17.1.apk+ or android-exoplayer-3.1.apk+ required. |
gpsInside("lat1,lng1,lat2,lng2,lat3,lng3...") |
Same as above but accepts a single argument quoted String representation of many latitude longitude pairs. In addition to improving performance this function allows other defined data to be used for example gpsInside(manhattanPolygon) . |
These functions require gpsLatitide
and gpsLongitude
to be set in the data. Screens will update these values automatically.
For testing in the admin interface, set a test location using the Set test data dialog. This is accessed by pressing the a=b button on the sequence tab or playback simulator.
More Functions and Values
Syntax | Description |
---|---|
random() |
Generates a random number between 0 and 1. For example random() < 0.5 returns true 50% of the time. Note: Generates a new random number every time it appears in a condition. |
random |
A random number between 0 and 1. A single number is generated and reused for evaluating all items in a stack. This is important for accurate division of probabilities between alternatives. #1 |
loopCount |
The number of loops of the main sequence since the player started. This makes it possible to only show an item every n loops. e.g. loopCount % 5 == 0 will only show the item every 5 loops of main sequence. |
stringContains(string, search) |
Returns true if the string contains the search . |
stringStartsWith(string, search) |
Returns true if the string starts with the search . |
stringEndsWith(string, search) |
Returns true if the string ends with the search . |
isDefined("name") |
Returns true if the data with the given name is defined and can be used in condition evaluation. Remember to quote the name! #2 |
isNullOrEmpty("name") |
Returns true if data with the given name is undefined, null or empty. Remember to quote the name! #2 |
#1 Requires standard player 3.8+ or any later player.
#2 Only available in signagenode-2023-10-18 or later.
Simplify list processing using strings
A common requirement is to show an item in a shared sequence on a subset of screens.
One way to do this is by assigning data to screen and accessing in a condition.
Example:
Screens include airportCode
in the data assigned with a value e.g. ANC
Condition to display item at 4 airports:
airportCode == "ANC" || airportCode == "BTR" || airportCode == "BUF" || airportCode == "CAK"
To simplify conditions involving lists of data, the string search functions above can help.
stringContains("ANC,BTR,BUF,CAK", airportCode)
For long lists this is more convenient and efficient than using multiple boolean operators.
Strict evaluation
Condition evaluation requires all variables to be defined or the condition will throw an error and the item will be skipped. When some variables may not be defined consider using short circuit evaluation and the isDefined()
and isNullOrEmpty()
functions to avoid errors.
Example:
isNullOrEmpty
("airportCode") || !stringContains("ATL", airportCode)
This example will show the item on all screens except those with airportCode set to "ATL".
Variable Scope and Order of Preference
Variables within the current evaluation scope can be accessed in conditions. The scope includes: current item data, current slot data, current sequence data, and screen data.
Screen data will override sequence data with the same name. This can be useful when setting defaults in the sequence data that will be overridden by specific screens to provide customisation.
The order of precedence is as follows: (Highest precedence used)
- Active item data
- Active slot data
- Active screen data
- Active sequence data (top to bottom when using base sequences)
Extended Scope
To evaluate outer sequence item conditions at the same time as an inner sequence item condition the scope must be extended.
This is used for schedule sequences, when a changing hour or day should break out of playing a long, looping inner sequence.
The following data in the outer sequence or outer sequence item extends the scope.
conditionScope=extend
It is also possible to access data from outer sequences if the outer sequence or outer sequence item includes the following:
dataScope=extend
Web page main sequence scope
When accessing data using the JavaScript DigitalSignage.getData(name)
function the main sequence (which may differ to current sequence) is also in scope. This can be useful for HTML based sequence frames.
Comments
0 comments
Please sign in to leave a comment.