Nodes

Length#

The Length node is used to determine the number of elements in an array. It takes an array as input and outputs the length of that array as an integer.

Inputs#

  • a (array): The input array to measure the length of. Defaults to an empty array if not provided.

Outputs#

  • result (integer): The length of the input array.

Configuration#

This node has no additional configuration options.

Usage#

  1. Connect an array to the a input of the Length node. This can be a static array, the output of another node, or an array variable.
  2. The Length node will output the number of elements in the connected array to its result output.
  3. Connect the result output to the input of another node or use it as needed in your spell.

Example#

Here's an example of how the Length node can be used in a spell:

  1. Create an Array node and configure it with the following elements: "apple", "banana", "orange".
  2. Create a Length node and connect the output of the Array node to its a input.
  3. Create a Debug node and connect the result output of the Length node to its message input.
  4. Run the spell. The Debug node will log the length of the array, which is 3 in this case.

Best Practices#

  • Use the Length node whenever you need to know the number of elements in an array. This is often useful for looping, validation, or conditional logic based on array size.
  • Remember that the Length node counts the top-level elements in the array. If the array contains nested arrays, those nested arrays will be counted as single elements.

Common Issues#

  • If the a input is left disconnected, the Length node will default to measuring an empty array and always output 0. Make sure to connect an array to the input.
  • The Length node only works with arrays. Attempting to connect other data types like objects, strings, or numbers will result in an error.

By using the Length node, you can easily determine the size of arrays in your Magick spells and make decisions or perform iterations based on that information.