8. Calculate totals and statistics for an array
Build this example in your Unreal project and compare the result at each step.
On this page
Now you will work with several numbers at once. Continue in BP_MiNumero and use a variable of your own.
- Create a variable Values of type Scientific Number. Change its container to Array and compile.
- In its default values, add five elements with Base 10, 20, 30, 40, and 50; leave Exponent at 0. You can also connect five Make Scientific Number nodes to a Make Array.
- Drag a Get of Values into the graph and connect the array to each operation in the table, testing one at a time.
- Connect their execution pins if they have them, and check success/error before displaying the result.
| Operation | Result with 10, 20, 30, 40, 50 | Result after changing 50 to 100 |
|---|---|---|
| Sum of Array | 150 | 200 |
| Average of Array | 30 | 40 |
| Min of Array | 10 | 10 |
| Max of Array | 50 | 100 |
- Stop Play, change the last element to 100, and repeat all four operations.
When finished: the sum and average should reflect the array change; the minimum should remain 10.