Evaluating Results
Processing the results of ActionSteps is central to XenoGuard. Often, these results need checking, converting, or further processing before they can be compared with other data or passed on to other actions. XenoGuard uses identifiers, including variables, to store results. Additionally, XenoGuard offers a direct result referencing mechanism for processing results. These concepts are detailed in the following section.
In XenoGuard, the term identifier represents names for different types of entities (data containers) within the script, including variables, parameters, results, and enums. The term refers to the name used to access and identify these entities. In a stricter sense, identifiers themselves do not represent the entities but rather serve as referential names, although the terms are often used interchangeably. |
---|
Working With Identifiers
XenoGuard distinguishes between four data management mechanisms, collectively referred to as identifiers. Each identifier has a unique name, a data type, and a value. The identifier's name is user-defined but must be unique within the script's context. The local context pertains to an individual ActionScript, while the global context applies to the entire workspace.
Identifier | Context | Data Type(s) | Description |
---|---|---|---|
Variable | Local or Global | All data types | Any variable |
Parameters | Local | All data types | Input parameters of a script |
Result | Local | All data types | Result parameters of a script |
Enum | Local or Global | Text | Symbolic designation of constants |
Data types and enumerations are presented later in sections 4.5 and 4.6.
XenoGuard provides separate actions for the four identifier types, found in the Identifier folder of the Programming group (refer next figure). While the first four actions define an identifier, you can assign a value with the Set Identifier action.
Variables, parameters, results, and enums share the following characteristics:
- Containers for Data: They serve as holders for values or information needed during script execution.
- Access and Use of Data: They enable access to the data stored in them, allowing actions to perform calculations and check conditions.
- Naming: Identifiers are used to access the stored data or to identify it within the script.
- Data Types: Each has a specific data type that defines the kind of data they can store, ensuring type safety and proper operation in calculations.
- Modifiability: Some identifiers vary in their modifiability properties. For instance, enums cannot be changed during execution, whereas other identifiers have attributes controlling this.
To illustrate, consider a script for calculating the volume of a cylinder using the formula:
V = π r ²h
The script requires the radius (r) and cylinder height (h) as input parameters and returns the volume (V). The next figure shows the script:
Lines 1 to 4 define four identifiers. The variable Pi defines the mathematical constant. The script receives the radius and height as input parameters, and the result is stored in the volume identifier. All identifiers are of floating-point data type, and the input parameters are pre-set with valid values: radius = 5 and height = 10 (units unspecified).
The calculation occurs in lines 5 to 8, with the final result rounded to two decimal places. The script first calculates the radius squared using the Power action. The result (25) is then multiplied by Pi and the cylinder height.
The script's incorporation of intermediate results from individual actions into the calculation is noteworthy. For instance, the first multiplication requires the result of the Power action, while the second multiplication needs the result of the first multiplication. This is achieved through referencing.
Accessing Result Values via Referencing
References allow access to an action's results without additional auxiliary variables. To create a reference via drag and drop:
- Move the mouse pointer to the source parameter you want to reference, like the Result parameter of the Power action (see figure below).
- Click the source parameter, hold down the left mouse button, and drag it to the target parameter, such as Factor 1 of the multiplication action.
- When the cursor is over the target parameter, release the mouse button. The reference path is automatically created in text form (e.g., ResultList ► Result).
Once the reference is set, two red arrowheads or a red arrow will appear in both the source and target actions, indicating the direction of data flow. The next image shows the result of the first multiplication being used.
Accessing Identifier Values
Actions can directly read and process values from an identifier, like the Power action in line 5 reading the radius parameter.
Using an Identifier with the Mouse:
- Move the mouse pointer over the identifier definition, e.g., Define Parameter "radius".
- Click the action, hold down the left mouse button, and drag it to the target parameter, like the Base parameter of the Power action.
- Once the cursor is over the target parameter, release the mouse button. The identifier name appears in blue.
Actions can also store their results in an identifier in the same way. For example, the Round action saves the rounded result directly in the result identifier, making a separate assignment unnecessary.
Tips for Working with Identifiers
Meaningful naming of identifiers is crucial for making ActionScripts more understandable and easier to maintain. The following strategies and conventions are useful for naming:
- Use Descriptive Names: Choose names that clearly and precisely describe the purpose and content of the identifier. Avoid abbreviations or cryptic names that are hard to understand. A good name should immediately inform other developers about the type of data the identifier contains. With XenoGuard, names may include spaces and special characters.
- Maintain Consistency: Adhere to a consistent naming convention for ease of understanding by other developers. While specific naming conventions like CamelCase or snake_case are not mandatory (since spaces are generally allowed), valid conventions could be First Name, My Street, or Encrypted Password.
- Avoid Reserved Words: Stay clear of reserved words or keywords to avoid confusion.
- Define at the Beginning of the Script: It's advisable to define all identifiers at the start of your script. Organizing them by type - starting with variables, followed by parameters, results, and enums - greatly enhances readability. For scripts with numerous identifiers, organizing all definitions in a Region block can be helpful. This allows you to show or hide this block as needed, further improving clarity.