-
Notifications
You must be signed in to change notification settings - Fork 0
Reading an attribute
The dot notation is used to read or write an attribute.
If you are referencing the attribute of an instance in an instance set (variable or expression), you need to use the dot notation to access any of its attributes. For example:
cabin height = /R1/Cabin.Height
Attributes of the local instance need not be qualified. Assuming we have an instance of Aircraft and a single instance of some other Aircraft in a target variable we could write:
closing speed = target.Air speed - Air speed
The Speed element is understood to represent the local Aircraft instance as distinct from the target Aircraft’s speed.
This means that no local variables may be named to match any local attribute. So, if you have a class called Aircraft with attributes Tail number, Altitude, Airspeed and Heading, you cannot use any of those names for local variables.
A scalar variable can be assigned an attribute value from an instance reference set that contains exactly one instance. Let’s say that an instance of Shaft wants to save the height of its Cabin.
cabin height = /R1/Cabin.Height
If the RHS yields zero or many instances, there will be a runtime error. The above example is taken from the Elevator Case Study where there is an unconditional to-one association and it is assumed that all instances have been created at initialization. Therefore, there is no need to check in this case.
If, on the other hand, it is possible for the RHS to yield the empty set, you should verify that this is not the case before making the scalar variable assignment.
Here, an Aircraft instance has a 1:0..1 association with an assigned runway. So we must verify that the my runway variable is not empty before performing the scalar assignment.
my runway .= /taxi to/Runway
my runway? takeoff heading = my runway.Heading : norunway -> ME
Or you could do this:
found runway = /taxi to/Runway
// implicit conversion to boolean
(found runway)? takeoff heading = my runway.Heading
(!found runway)? norunway -> ME
Note the use of the = assignment operator instead of .=. Since the empty set is false and one or more instances true, we can perform an implicit conversion to a boolean scalar variable. There isn’t much point in doing this here since you could just evaluate the instance set as we did in the previous example. But, in a more complex activity, you may find a need for a boolean variable assigned in this manner.
Copyright 2020, 2021, 2022, 2023, 2025 © Leon Starr under MIT Open Source License
- Why they are problematic
- Instance attribute creation values
- Boolean values
- Special values
- Enumerated values
- Action block
- Statement
- Single line action
- Multiple dependent actions on a single line
- An action spread across multiple lines
- A conditional group of single line actions
- Comments
- Finding instances
- Attribute access
- Creation and deletion
- Subclass migration
- Creating a table from a class
- Creating a table with a definition
- Converting a table into a class
- Set operations on tables
- Set comparisons on tables
- Join
- Rename
- Extend
- Aggregation
- Rank
- Image
- Input values
- Signatures and name doubling
- Output values
- Execution order
- Sequential execution
- Conditional execution
- Signals
- Scrall has no for_each action
- Iteration