Compute
Icon
Function
This is used when independent computations are needed in the process.
Key Points
-
Creating a New Formula
Click the "New Formula" button to add a formula input box. Enter the formula here.
-
Operating Mechanism
The system performs computations from top to bottom in order.
-
Adjusting Computation Order
When hovering over an input box, a drag symbol appears on the left. Drag it to move up and down.
General Methods for input box
Formula Syntax
-
Basics
You need to input an equation into the input box, indicating that the data object on the left side of the equation is assigned the expression on the right. Otherwise, a warning will appear.
- Formula refers to the assignment of data components and is in the form of an equation, such as
B = 2 * A
. - The expression can be understood as only the right side of the formula, used for specific values. For example, local variable B can be expressed as twice the global variable A in the initial assignment column
2 * A
.
-
Autocomplete
-
At any time, when you click the input box to enter the input state, a drop-down suggestion list will appear. It lists recommended content that you might use, presented by category with brief explanations. Click to select and the content will be automatically completed in the current input box.
-
The top example is the most commonly used input content recommendation at the current location.
-
The autocomplete feature provides predictive suggestions, allowing for swift and accurate completion of expressions or formulas as you type.
-
Expression Syntax
HoloBit's expression is closer to Python's usage habits, such as List.pop(), Dict[key], PI**2, ...
Expressions can use the following: data components and their methods, keywords, built-in properties of entities, built-in methods of entity objects, global functions and operators, various data format values, etc.
Dot Syntax
- The
object.xxx
format can be used in the following cases - When accessing the properties of an entity object, use
entity_object.property_name
. - When accessing the methods of an entity object, use
entity_object.method
. - When accessing the methods of a data object, use
data_object.method
. - When accessing the value corresponding to the Dict with String format keys, use
Dict_object.Key
. - When accessing the output data of the previous process component, use
component_name.output_key
. - After the action, to access the output data of this component, use
This.output_key
. - When accessing the variable port data of the preceding process call object, use
call_object.port_name
.
Index Syntax
- The
object[xxx]
format can be used in the following cases - To access Dict data, use
Dict_object[Key]
. - To access List data, use
List_object[Index_Number]
. - To access any individual within an entity, use
entity[ID]
.
For related details, please refer to the Detailed Specifications section.
Recognition Priority of Object Names
For any name that appears in the formula, the system recognizes it according to the following priority order:
- Keywords in the component's formula bar, like the default keyword
Entity
for Ask or Entity Statistics components, the keywordThis
for components with output data, etc. - Within the process: Randomly recognizes preceding process components and data components.
- Outside the process: Level by level to the parent process.
- Outside the process but within the entity: Entity individual properties are prioritized over observer properties.
- Outside the entity: Global data objects.
When at the same level, it will be recognized randomly.
The names of process components in the model and data components at different levels may overlap, and the system identifies them according to the above priorities.
- This means that when using a certain name in a formula at a certain location, other objects with the same name are shielded and inaccessible.
- The system will provide warnings about name conflicts.
- Name conflicts don't necessarily prevent the model from running, but they can lead to unexpected confusion. When naming any object that might appear in expressions, try to use unique names. Understanding the above system's recognition priorities may help explain possible confusion when you are using objects with the same name.
Consider a scenario where a formula in a Compute component is v = a.b
:
- There's a preceding Ask component named a (red)
- A local process variable also named
a
(yellow) - A global variable also named
a
(green)
In this case, if you use a in the formula:
- The system will randomly recognize a as either the Ask component or the local variable.
- The global variable a will not be accessible in this formula.
- The system will display a warning about the name conflict in the Console.
From this example, you can better understand why it's crucial to avoid name conflicts. They can lead to unpredictable behavior in your model, even if the model still runs.
Example
Global functions are used for computation.