Those declarations sections which declare items that are listed in a window of values (sensors, controls, variables and smartcabs) can have one or more groups defined before the actual items themselves.
A group instruction defines the order in which the items are displayed in the appropriate window, and possibly groups items together on a single line.
The best way to explain this is with an example:
Lets suppose that our layout is made up of several track sections (and possibly other things we are not considering here). Each track section has the following variables associated with it:
- state:
- some indication of whether the track is in use, reserved for a train, or whatever.
- train:
- which train is using the section.
- next:
- which section the train will go to next.
- prev:
- which section the train has just come from.
We have sections called s1, s2, s3 etc.
Therefore we might have the following variables declaration:
We would naturally like the variables to be grouped in the variables window like this:Variables: s1state, s2state, s3state s1train, s2train, s3train s1next, s2next, s3next s1prev, s2prev, s3prev
s1state s1train s1next s1prev s2state s2train s2next s2prev s3state s3train s3next s3prev
To achive this we would use the following group statement:
This would produce a window like this:Variables: group tracks (state, train, next, prev)=(s1, s2, s3) s1state, s2state,
In the group statement the first list is a list of column names, and the second is a list of row names. A declaration item is considered part of the group if:
Take the name of the item. Look for a row name in the name (such as s1 is s1state, or states1, or even sts1ate). If such a name is found then remove it and test to see if what remains matches one of the column names in the same group.
The identified items are displayed in the order defined in the group statement, with the row and column labels attached.
Note that the group statement merely tells tcc how to arrange some variables (or sensors or controls) in their window. It does NOT declare the variables themselves. For a short form of variable declaration see the STRUCT statement.
The row name list could instead be an array name, such as in:
This declares six cab-for-train (cabtr) variables, six length of train variables and six speed of train variables, and is similar to:Variables: Group: trains (cab, len, sp)=(tr[]) cabtr [6], lentr [6], sptr [6]
Except that the first declaration makes an array that can be accessed as an array, and the second for would simple make 18 independent variables.Group: trains (cab, len, sp)=(tr1, tr2, tr3, tr4, tr5, tr6) cabtr1, cabtr2, cabtr3, cabtr4, cabtr5, cabtr6 lentr1, lentr2, ...
Any items not defined in any group are shown at the end of the window, in the order they appear in the rest of the declaration.
Back to declarations page