Skip to main content

Formula-Generated Array

This node generates an array of numbers based on a mathematical formula.

The Formula-Generated Array node (MFAG) creates a dataset by evaluating a formula for a sequence of indices.

The Formula-Generated Array node creates a list of numbers where each item is calculated using a formula. The formula uses x as the index (0, 1, 2, ...). This is incredibly useful for generating curves, graphs, look-up tables, or procedural data sequences.

Inputs

Parameters

DataDescription
Math FormulaThe formula to evaluate for each index x. Example: x * 10, sin(x / 10). Default: exp(-x / 15).
Array LengthThe number of items to generate. Default: 10. Max: 10,000.

Actions

SignalDescription
DoTriggers the generation of the array.

Outputs

General

DataDescription
ItemsThe generated array of numbers (wrapped in objects).
CountThe number of items in the generated array.
IdThe ID of the generated collection.
First Item IdThe ID of the first item in the collection (useful for quick access).

Signals

SignalDescription
DoneTriggered when the array generation is complete.

Usage

Example Use Cases

  1. Graph Plotting: Generate data points for a sine wave.
    • Formula: sin(x * 0.1)
    • Length: 100
  2. Level Progression: Calculate XP required for each level.
    • Formula: 100 * (x ^ 1.5)
  3. Linear Sequence: Simple counting numbers.
    • Formula: x

Detailed Behavior

  1. Iteration: The node loops from x = 0 to Array Length - 1.
  2. Evaluation: For each x, it evaluates the formula using mathjs.
  3. Output Format: The result is a standard XFORGE Collection/Array where each item is an object: { "0": value }. This allows it to be used with Repeaters and other data nodes.

Troubleshooting

  • Performance: Generating very large arrays (near 10,000) with complex formulas can be slow.
  • Invalid Formula: If the formula fails for any specific x (e.g., division by zero), the entire generation aborts.