VASSAL Reference Manual

Home > Module > Expressions > Sum & Count Expressions


Sum and Count Functions

Overview

Vassal provides a range of functions to allow efficient counting of pieces and summing the values of numeric properties that they hold.

Depending on what is known about the location of the pieces that you want to Sum or Count, there are different sets of functions that can do this efficiently:

  • Stack based - Pieces in the same stack as the current piece

  • Location based - Pieces in the same location as the current piece, or in a known location

  • Zone based - Pieces in the same Zone as the current piece, or in a known Zone

  • Map based - Pieces on the same Map as the current piece, or on a known Map

  • Attachment based - Pieces attached to the current piece

  • Mat based - Pieces on the same mat as the current piece

  • Range based - Pieces within a specified range of the current piece, or a known location

  • Generic - Pieces where the location is not known

  • Summary - Function Summary

Note
When any of these functions are used in a piece trait, then if that source piece also passes whatever selection options are used, then the source piece will also be included in the Sum or Count returned.

Trait Only Functions

Some functions are marked with the notation [ Trait Only ]. These functions can only be used inside expressions in Piece Traits, or in components where they will be applied to individual pieces.

The fields in components where these functions can be used are:

  • The Additional matching expression field in any Global Key Command

Using these functions in any other context (for example a Map movement report) will return a result of 0.

Common fields

Property Name

The Property name used in a function can be the name of an actual property (which should be entered in quotes as "propName"), or can be another expression that evaluates to a property name.

All Sum functions total the numeric value for the specified property name (prop) in each of the matching pieces.

If a matching piece does not specify the value of the property, or if the value of the property is not numeric, then nothing will be added to the sum for that piece.

Some Count functions take a property name (prop) argument and will only add 1 to the count if that property has a non-blank value for a piece.

Note
The Property Name in a Count function is a convenient shorthand for using "{ property != \"\" }" in an expression.
Property Match Expression

When an expression is used in any Sum or Count function, it must have the special format defined for Property Match Expressions.

See PropertyMatchExpression.html for more information.

Additionally, the expression must be supplied as a full Beanshell expression (including the curly braces {}), inside double quotation marks, and you must use a special syntax \" for any double quotes included inside the expression.

CountStack("{Strength>3}")
CountStack("{StepCount < 2 && Army == \"Russian\"}")
Note
The BeanShell Function builder will automatically add the special syntax for you.
Zone, Location and Map Names

The Zone Sum and Count functions take a Zone name and a Map name and will only act on pieces currently located in the named Zone on the named Map.

The Location Sum and Count functions take a Location name and a Map Name and will only act on pieces currently on the named Map in Locations with the specified Location Name.

The Map, Zone and Location names used in a function can be the name of an actual Map, Zone or Location (which should be entered in quotes like "zoneRight"), or can be another expression that evaluates to a Zone or Location name.

Function Summary

SumStack

Sum a property in pieces in a Stack

CountStack

Count the number of pieces in a Stack

SumLocation

Sum a property in pieces in a Map location

CountLocation

Count the number of pieces in a Map location

SumZone

Sum a property in pieces in a Zone

CountZone

Count the number of pieces in a Zone

SumMap

Sum a property in pieces on a Map

CountMap

Count the number of pieces on a Map

SumMat

Sum a property in pieces in a Mat and Cargo group

CountMat

Count the number of pieces in a Mat and Cargo group

SumAttach

Sum a property in pieces in an Attachment group

CountAttach

Count the number of pieces in an Attachment group

SumRange

Sum a property in pieces within range

SumRangePx

Sum a property in pieces within range (in pixels)

CountRange

Count the number of pieces within range

CountRangePx

Count the number of pieces within range (in pixels)

Sum

Sum a property in pieces that match an expression

Count

Count the number of pieces that match an expression

Stack based functions

Use these functions when you want to Sum or Count pieces that are in the same Stack as the current piece.

Only pieces in exactly the same Stack as the source piece (including the source piece) will be included. Other pieces that may be in the same location, but not in the same Stack, such as non-stacking pieces, or pieces stacked in other Game Piece Layers, will not be totalled.

Note
A Deck is a special kind of Stack, so Stack functions also work to Sum & Count pieces in a Deck.
SumStack Returns the total of the specified property in pieces in the same Stack as the current piece.

SumStack(prop)

[ Trait Only ]

All pieces in the current stack will be included.

SumStack("Strength")

Sum the value of the property Strength in all pieces in the current stack.

SumStack(prop, expression)

[ Trait Only ]

Only pieces that match the supplied Property Match Expression will have their value of the property included in the total.

SumStack("Strength", "{Size > 5}"})

Sum the value of the property Strength in all pieces in the current stack that have a value of more than 5 for the Size property.

CountStack Returns the count of pieces in the same Stack as the current piece.

CountStack()

[ Trait Only ]

Count all pieces in the current Stack.

CountStack()

Just a straight count of the pieces in the target piece’s Stack.

CountStack(prop)

[ Trait Only ]

Count the number of pieces in the current Stack, that have a non-blank value for the named property.

CountStack("Strength")

Count the number of pieces that have some value for the Strength property.

CountStack(expression)

[ Trait Only ]

Count the number of pieces in the current Stack that match the supplied expression.

CountStack("{Army==\"Russian\"})

Count the number of pieces (including the source piece) that have a Property named 'Army' with a value of 'Russian'.

CountStack(prop, expression)

[ Trait Only ]

Count the number of pieces in the current Stack that have a non-blank value for the named property AND that match the supplied expression.

CountStack("Strength", "{Army==\"Russian\"})

Count the number of pieces (including the source piece) that have some value for the Strength property AND that have a Property named 'Army' with a value of 'Russian'.

Location based functions

Use these functions when you want to Sum or Count pieces that have the same Location Name as the current piece or are in a known named Location on a specific map.

The Location Name might be a Zone name, a region name or a HexGrid location, depending on how the Grid Location naming is set up on the target piece’s map.

The pieces do not necessarily need to be in exactly the same place, (or even on the same Map!) as long as they have the same value for the LocationName property.

SumLocation Returns the total of the named property in pieces in a specified Location.

SumLocation(prop)

[ Trait Only ]

All pieces with the same Location Name as the current piece will be included.

SumLocation("Strength")

Sum the value of the property Strength in all pieces with the same Location Name as the current piece.

SumLocation(prop, expression)

[ Trait Only ]

Only pieces with the same Location Name as the current piece AND that match the supplied Property Match Expression will have their value of the property included in the total.

SumLocation("Strength", "{Unit==true"})

Sum the value of the property Strength in all pieces with the same Location Name as the current piece, that also have a value of true for the Unit property.

SumLocation(prop, location, map)

Only include pieces at the specified location on the specified Map.

SumLocation("Strength","B-06","East")

Sum the value of the Strength property in Location B-06 on the Map named East.

SumLocation(prop, location, map, expression)

Only include pieces at the specified location on the specified Map that also match the supplied Property Match Expression.

SumLocation("Strength",LastLocation,"East", "{SuppressedCount > 1}")

Sum the value of the Strength property in the Location recorded in the LastLocation property on the Map named East, that also have a value of more than 1 for the SuppressedCount property.

CountLocation Returns the count of the number of pieces in a specified Location.

CountLocation()

[ Trait Only ]

Count pieces with the same Location Name as the current piece.

CountLocation()

Count the number of pieces with the same Location Name as the current piece.

CountLocation(prop)

[ Trait Only ]

Count pieces with the same Location Name as the current piece AND that have a non-blank value for the named property.

CountLocation("Strength")

Count the number of pieces that have a non-blank value for the property Strength in all pieces with the same Location Name as the current piece.

CountLocation(expression)

[ Trait Only ]

Count pieces with the same Location Name as the current piece AND that match the supplied Property Match Expression.

CountLocation("{Size==2}")

Count the number of pieces with the same Location Name as the current piece, that also have a value of 2 for the Size property.

CountLocation(prop, expression)

[ Trait Only ]

Count pieces with the same Location Name as the current piece AND that have a non-blank value for the named property AND that match the supplied Property Match Expression.

CountLocation("Strength","{Size==2}")

Count the number of pieces with the same Location Name as the current piece, that also have a non-blank value for the Strength and have a value of 2 for the Size property.

CountLocation(location, map)

Count pieces at a specified location on the specified Map.

CountLocation("B-06","East")

Count the number of pieces at Location B-06 on the Map named East.

CountLocation(location, map, prop)

Count pieces at the specified location on the specified Map that have a non-blank value for the named property.

CountLocation("B-06","East", "Suppressed")

Count the number of pieces at Location B-06 on the Map named East that have a non-blank value for the property Suppressed.

CountLocation(location, map, expr)

Count pieces at the specified location on the specified Map that match the supplied Property Match Expression

CountLocation("B-06","East", "{Suppressed==2}")

Count the number of pieces at Location B-06 on the Map named East that have a value of 2 for the property Suppressed.

CountLocation(location, map, prop, expr)

Count pieces at the specified location on the specified Map that have a non-blank value for a property and that match a Property Match Expression

CountLocation("B-06","East", "CombatType", "{Suppressed==2}")

Count the number of pieces at Location B-06 on the Map named East that have a non-blank value for the CombatType property and that have a value of 2 for the property Suppressed.

Zone based functions

Use these functions when you want to Sum or Count pieces that are either in the same Zone as the current piece or are in a known Zone on a specific map.

If these functions are used within a piece trait, then that piece may be included in the total if it also meets the requirements.

SumZone Returns the total of the named property in pieces in a particular Zone.

SumZone(prop)

[ Trait Only ]

All pieces in the same Zone as the current piece, including the current piece, will have their value for the specified property added to the total.

SumZone("Strength")

Sum the value of the property Strength in all pieces in the same Zone as the current piece.

SumZone(prop, expression)

[ Trait Only ]

Only pieces in the same Zone as the current piece AND that match the supplied Property Match Expression will have their value of the property included in the total.

SumZone("Strength", "{Unit==true"})

Sum the value of the property Strength in all pieces in the same Zone as the current piece, that also have a value of true for the Unit property.

SumZone(prop, zone, map)

Only include pieces in the specified Zone on the specified Map.

SumZone("Strength","Repair","East")

Sum the value of the Strength property in Zone Repair on the Map named East.

SumZone(prop, location, map, expression)

Only include pieces in the specified Zone on the specified Map that also match the supplied Property Match Expression.

SumZone("Strength",LastZone,"East", "{SuppressedCount > 1}")

Sum the value of the Strength property in the Zone recorded in the LastZone property on the Map named East, that also have a value of more than 1 for the SuppressedCount property.

CountZone Returns the count of the number of pieces in a Zone.

CountZone()

[ Trait Only ]

Count pieces in the same Zone as the current piece.

CountZone()

Count the number of pieces in the same Zone as the current piece.

CountZone(prop)

[ Trait Only ]

Count pieces in the same Zone as the current piece AND that have a non-blank value for the named property.

CountZone("Strength")

Count the number of pieces that have a non-blank value for the property Strength in all pieces in the same Zone as the current piece.

CountZone(expression)

[ Trait Only ]

Count pieces in the same Zone as the current piece AND that match the supplied Property Match Expression.

CountZone("{Size==2}")

Count the number of pieces in the same Zone as the current piece, that also have a value of 2 for the Size property.

CountZone(prop, expression)

[ Trait Only ]

Count pieces in the same Zone as the current piece AND that have a non-blank value for the named property AND that match the supplied Property Match Expression.

CountZone("Strength","{Size==2}")

Count the number of pieces in the same Zone as the current piece, that also have a non-blank value for the Strength and have a value of 2 for the Size property.

CountZone(zone, map)

Count pieces in the specified Zone on the specified Map.

CountZone("DeadPool","East")

Count the number of pieces in Zone DeadPool on the Map named East.

CountZone(zone, map, prop)

Count pieces in the specified Zone on the specified Map that have a non-blank value for the named property.

CountZone("Retired","East", "Suppressed")

Count the number of pieces in Zone Retired on the Map named East that have a non-blank value for the property Suppressed.

CountZone(zone, map, expr)

Count pieces in the specified Zone on the specified Map that match the supplied Property Match Expression

CountZone("B-06","East", "{Suppressed==2}")

Count the number of pieces in Zone B-06 on the Map named East that have a value of 2 for the property Suppressed.

CountZone(location, map, prop, expr)

Count pieces in the specified Zone on the specified Map that have a non-blank value for a property and that match a Property Match Expression

CountZone("B-06","East", "CombatType", "{Suppressed==2}")

Count the number of pieces in Zone B-06 on the Map named East that have a non-blank value for the CombatType property and that have a value of 2 for the property Suppressed.

Map based functions

Use these functions when you want to Sum or Count pieces that are either on the same Map as the current piece or are on a specific map.

If these functions are used within a piece trait, then that piece may be included in the total if it also meets the requirements.

SumMap Returns the total of the named property in pieces on a particular Map.

SumMap(prop)

[ Trait Only ]

All pieces on the same Map as the current piece, including the current piece, will have their value for the specified property added to the total.

SumMap("Strength")

Sum the value of the property Strength in all pieces on the same Map as the current piece.

SumMap(prop, expression)

[ Trait Only ]

Only pieces on the same Map as the current piece AND that match the supplied Property Match Expression will have their value of the property included in the total.

SumMap("Strength", "{Unit==true"})

Sum the value of the property Strength in all pieces on the same Map as the current piece, that also have a value of true for the Unit property.

SumMap(prop, map)

Sum the value of the property in pieces on the specified Map.

SumMap("Strength", "East")

Sum the value of the Strength property in pieces on the Map named East.

SumMap(prop, map, expression)

Only include pieces on the specified Map that also match the supplied Property Match Expression.

SumMap("Strength",LastMap, "{SuppressedCount > 1}")

Sum the value of the Strength property in pieces on the Map recorded in the LastMap property AND that also have a value of more than 1 for the SuppressedCount property.

CountMap Returns the count of the number of pieces on a Map.

CountMap()

[ Trait Only ]

Count pieces on the same Map as the current piece.

CountMap()

Count the number of pieces on the same Map as the current piece.

CountMap(prop)

[ Trait Only ]

Count pieces within the same Map as the current piece AND that have a non-blank value for the named property.

CountMap("Strength")

Count the number of pieces that have a non-blank value for the property Strength in all pieces on the same Map as the current piece.

CountMap(expression)

[ Trait Only ]

Count pieces on the same Map as the current piece AND that match the supplied Property Match Expression.

CountMap("{Size==2}")

Count the number of pieces on the same Map as the current piece, that also have a value of 2 for the Size property.

CountMap(prop, expression)

[ Trait Only ]

Count pieces on the same Map as the current piece that have a non-blank value for the named property AND that match the supplied Property Match Expression.

CountMap("Strength","{Size==2}")

Count the number of pieces on the same Map as the current piece that have a non-blank value for the property Strength and have a value of 2 for the Size property.

CountMap(map)

Count all pieces on the specified Map.

CountMap("East")

Count the number of pieces on the Map named East.

CountMap(map, prop)

Count pieces on the specified Map that have a non-blank value for the named property.

CountMap("East", "Suppressed")

Count the number of pieces on the Map named East that have a non-blank value for the property Suppressed.

CountMap(map, expr)

Count pieces on the specified Map that match the supplied Property Match Expression

CountMap("East", "{Suppressed==2}")

Count the number of pieces on the Map named East that have a value of 2 for the property Suppressed.

CountMap(map, prop, expr)

Count pieces on the specified Map that have a non-blank value for a property and that match a Property Match Expression

CountMap("East", "CombatType", "{Suppressed==2}")

Count the number of pieces on the Map named East that have a non-blank value for the CombatType property and that have a value of 2 for the property Suppressed.

Attachment based functions

Use these functions to Sum or Count values on pieces that are currently Attached to the source piece using the Attachment trait.

Note
The Attachment functionality allows pieces to be attached to themselves. If this is the case, then the current piece will be included in the Sum or Count returned by these functions.
SumAttach Returns the total of the named property in pieces attached to the current piece.

SumAttach(attachment, prop)

[ Trait Only ]

Sum a property across all pieces attached to the current piece using the named Attachment.

SumAttach("Grouped", "Strength")

Sum the value of the property Strength in all pieces attached to the current piece by the Grouped Attachment.

SumAttach(attachment, prop, expression)

[ Trait Only ]

Sum a property across all pieces attached to the current piece using the named Attachment AND that matches the supplied Property Match Expression.

SumAttach("G1", "Strength", "{Unit==true"})

Sum the value of the property Strength in all pieces attached to the current piece by Attachment G1 AND that has a value of true for the Unit property.

CountAttach Count the number of pieces attached to the current piece.

CountAttach(attachment)

[ Trait Only ]

Count the number of pieces attached to the current piece using the named Attachment.

CountAttach("Grouped")

Count the number of pieces attached to the current piece by the Grouped Attachment.

CountAttach(attachment, prop)

[ Trait Only ]

Count the number of pieces attached to the current piece using the named Attachment AND that have a non-blank value for the named property.

CountAttach("G1", "Unit"})

Count the number of pieces attached to the current piece by the G1 attachment that also have a non-blank value for the Unit property.

CountAttach(attachment, expression)

[ Trait Only ]

Count the number of pieces attached to the current piece using the named Attachment AND that match the supplied Property Match Expression.

CountAttach("G1", "{Unit==true"})

Count the number of pieces attached to the current piece by the G1 attachment and that have a value of true for the Unit property.

CountAttach(attachment, prop, expression)

[ Trait Only ]

Count the number of pieces attached to the current piece using the named Attachment AND that have a non-blank value for the named property AND that match the supplied Property Match Expression.

CountAttach("G1", "StepCount", "{Unit==true"})

Count the number of pieces attached to the current piece by the G1 attachment and that have a non-blank value for the StepCount property and that have a value of true for the Unit property.

MaxAttach Find the highest value of a Property among attached pieces.

MaxAttach(attachment, prop)

[ Trait Only ]

Find the highest value of the named Property among pieces attached by the named Attachment. Returns 0 if no pieces containing the property are attached.

MaxAttach("Group", "Strength")

Find the highest value of the Strength property among the pieces attached to the current piece by the Group Attachment.

MinAttach Find the lowest value of a Property among attached pieces.

MinAttach(attachment, prop)

[ Trait Only ]

Find the lowest value of the named Property among pieces attached by the named Attachment. Returns 0 if no pieces containing the property are attached.

MinAttach("Group", "Bravery")

Find the lowest value of the Bravery property among the pieces attached to the current piece by the Group Attachment.

Mat based functions

Use these functions to Sum or Count values on pieces that are part of a Mat and Cargo relationship.

For all Mat based functions, the asking piece can either be a Mat or a Mat Cargo, and a Mat Cargo can only be attached to at most one Mat. If the piece is not a Mat, and/or if it is a Mat Cargo piece not presently on a Mat, then only the piece itself is checked.

Note
The current piece calling the Mat-based functions will always check and potentially include itself in the total if it passes the requirements.
SumMat Returns the total of the named property in the current Mat/Cargo group.

SumMat(prop)

[ Trait Only ]

Sum a property across all pieces in the current Mat and Cargo group.

SumMat("Strength")

Sum the value of the property Strength in all pieces in the current Mat/Cargo group.

SumMat(prop, prop, expression)

[ Trait Only ]

Sum a property across all pieces in the current Mat/Cargo group AND that matches the supplied Property Match Expression.

SumMat("Strength", "{Unit==true"})

Sum the value of the property Strength in all pieces in the current Mat/Cargo group AND that has a value of true for the Unit property.

CountMat Count the number of pieces in the current Mat/Cargo group.

CountMat()

[ Trait Only ]

Count the number of pieces in the current Mat/Cargo group.

CountMat()

Count the number of pieces in the Mat/Cargo group for the current piece.

CountMat(prop)

[ Trait Only ]

Count the number of pieces in the current Mat/Cargo group AND that have a non-blank value for the named property.

CountMat("Unit"})

Count the number of pieces Count the number of pieces in the current Mat/Cargo group that also have a non-blank value for the Unit property.

CountMat(expression)

[ Trait Only ]

Count the number of pieces in the current Mat/Cargo group AND that match the supplied Property Match Expression.

CountMat("{Unit==true"})

Count the number of pieces in the current Mat/Cargo group and that have a value of true for the Unit property.

CountMat(prop, expression)

[ Trait Only ]

Count the number of pieces in the current Mat/Cargo group AND that have a non-blank value for the named property AND that match the supplied Property Match Expression.

CountMat("G1", "StepCount", "{Unit==true"})

Count the number of pieces in the current Mat/Cargo group and that have a non-blank value for the StepCount property and that have a value of true for the Unit property.

Range based functions

Use these functions to Sum or Count values on pieces that are with a certain range of a source piece, or of a known location.

Each function has two versions.

The first version assumes the range is in the 'native' format of the from location (Grid Units). If a Hex or Square grid exists at that location, then the Range will be assumed to be in appropriate grid cells (hexes or squares). If there is no grid, or an Irregular grid at that location, then the range is assumed to be in pixels.

The second Px version of the function forces the Range to be checked in Pixels, even if a Hex or Square grid exists at the From location.

All Range functions take a minimum and a maximum range as parameters. Pieces will be included in the Count or Sum if their range from the calling piece is greater than or equals to the minimum range and less than or equal to the maximum range.

Error checking is performed and a negative or non-numeric minimum range will be treated as 0. A non-numeric maximum range, or one that is less than the minimum range will be treated as equal to the minimum range.

Note
On maps with a Zoned Grid, the Grid at the From location is assumed to fill the entire Map for the purposes of the Range calculation.
Note
If a range-based function is called from within a Piece and a minimum range of 0 is specified, then the calling piece will be included in the Sum or Count returned.
Note
In range-based functions, a maximum range of 0 will only find pieces in EXACTLY the same X, Y location as the calling Piece.
SumRange Returns the total of the named property in pieces within range (in Grid Units) of the current piece

SumRange(min, max, prop)

[ Trait Only ]

Sum a property across all pieces within the specified range in Grid Units

SumRange(0, 0, "Strength")

Sum the value of the property Strength in all pieces in exactly the same X,Y location as the current piece.

SumRange(1, 2, "Strength")

Sum the value of the property Strength in all pieces in that are 1 or 2 grid units away. On a Hex map, this will be all units in adjacent hexes, or 2 hexes away.

SumRange(min, max, prop, expr)

[ Trait Only ]

Sum a property across all pieces within the specified range in grid units AND that match the supplied Property Match Expression.

SumRange(1, 1, "Strength", "{Army==\"German\"}")

Sum the value of the property Strength in pieces in the adjacent hexes that have a value of "German" for the Army property.

SumRangePx Returns the total of the named property in pieces within range (in pixels) of the current piece

SumRangePx(min, max, prop)

[ Trait Only ]

Sum a property across all pieces within the specified range in Pixels

SumRangePx(1, 100, "Strength")

Sum the value of the property Strength in all pieces within 100 pixels of the current piece, but excluding the current piece and any piece stacked in the same location as the current piece.

SumRangePx(min, max, prop, expr)

[ Trait Only ]

Sum a property across all pieces within the specified range in pixels AND that match the supplied Property Match Expression.

SumRangePx(0, 500, "Strength", "{Alien==true}")

Sum the value of the property Strength in pieces within 500 pixels that have a value of true for the Alien property.

CountRange Count the number of pieces within range (in Grid Units) of the current piece

CountRange(min, max)

[ Trait Only ]

Count all pieces within the specified range in Grid Units

CountRange(1, 5)

Count all pieces within 5 hexes of the current piece, but not in the same hex as the current piece.

CountRange(min, max, prop)

[ Trait Only ]

Count all pieces within the specified range in Grid Units AND that have a non-blank value for the named property.

CountRange(1, 5, "Russian")

Count all pieces within 5 hexes of the current piece, but not in the same hex as the current piece and that have a non-blank value for the Russian property.

CountRange(min, max, expr)

[ Trait Only ]

Count all pieces within the specified range in Grid Units that match the supplied Property Match Expression.

CountRange(1, 5, "{Army==\"Russian\"}")

Count all pieces within 5 hexes of the current piece, but not in the same hex as the current piece and that have a value of "Russian" for the Army property.

CountRange(min, max, prop, expr)

[ Trait Only ]

Count all pieces within the specified range in grid units that have a non-blank value for the named property AND that match the supplied Property Match Expression.

CountRange(0, 2, "Isolated", "{Army==\"German\"}")

Cout the pieces within 2 hexes of the current piece that have a non-blank value for the property Isolated AND that have a value of "German" for the Army property.

CountRangePx Count the number of pieces within range (in pixels) of the current piece

CountRangePx(min, max)

[ Trait Only ]

Count all pieces within the specified range in pixels

CountRangePx(1, 5)

Count all pieces within 5 pixels of the current piece, but not in the same X, Y location as the current piece.

CountRangePx(min, max, prop)

[ Trait Only ]

Count all pieces within the specified range in pixels AND that have a non-blank value for the named property.

CountRangePx(1, 500, "Alien")

Count all pieces within 500 pixels of the current piece, but not in the same X, Y position as the current piece and that have a non-blank value for the Alien property.

CountRangePx(min, max, expr)

[ Trait Only ]

Count all pieces within the specified range in pixels that match the supplied Property Match Expression.

CountRangePx(0, 500, "{Armed==true}")

Count all pieces within 500 pixels of the current piece, that have a value of true for the Armed property.

CountRangePx(min, max, prop, expr)

[ Trait Only ]

Count all pieces within the specified range in pixels that have a non-blank value for the named property AND that match the supplied Property Match Expression.

CountRangePx(0, 200, "Isolated", "{Army==\"German\"}")

Count the pieces within 200 pixels of the current piece that have a non-blank value for the property Isolated AND that have a value of "German" for the Army property.

Generic functions

These functions are provided for backwards compatibility, but are not recommended for general use as they are not efficient. When the location of the pieces to be summed or counted is not known, then every piece on the map (if known) or all maps (if not), must be checked to see if they need to be included.

Note
These plain Sum and Count functions are provided for backwards-compatibibility with modules created with earlier versions of Vassal and can have substantial performance cost as they must check all the pieces on the map or in the entire game against the expression.

Wherever possible, use the specific Sum and Count functions detailed above.
Sum Sum the total of a property across all pieces in the game

Sum(prop, expr)

Sum the value of a property across all pieces in the game that match the supplied Property Match Expression.+

Sum("Isolated", "{Army == \"Russian\" && Isolated > 0}")

Sum the value of the property Isolated across all pieces in the game that have a value of "Russian" for the Army property, and a value greater than 0 for the Isolated property.

Sum(prop, expr, map)

Sum the value of a property across all pieces on the named Map that match the supplied Property Match Expression.+

Sum("Isolated", "{Army == \"Russian\" && Isolated > 0}", "EastFront")

Sum the value of the property Isolated across all pieces on the Map named "EastFront" that have a value of "Russian" for the Army property, and a value greater than 0 for the Isolated property.

Count Count the number of pieces in the game

Count(expr)

Count the number of pieces in the game that match the supplied Property Match Expression.+

Count("Isolated", "{Army == \"Russian\" && Isolated > 0}")

Count the number of pieces in the game that have a value of "Russian" for the Army property, and a value greater than 0 for the Isolated property.

Count(expr, map)

Count the number of pieces on the named Map that match the supplied Property Match Expression.+

Count("{Army == \"Russian\" && Isolated > 0}", "EastFront")

Count the number of pieces on the Map named "EastFront" that have a value of "Russian" for the Army property, and a value greater than 0 for the Isolated property.