Skip to main content

ForEach

The for each effect allows you to iterate over an array and perform an effect (apply) for each of its values.

JSON Format

{
"type": "forEach",
"components": ...,
"apply": ...,
"for_each_value_key": ...,
"synchronous": ...
}

Fields

FieldTypeRequiredDescription
componentsStatFormulaComponentThe array of values to iterate on. This stat formula must return an array.
applyEffectThe effect to apply to each of the values in the components array. Anything inside this effect can make use of the $forEachValue stat, which will contain the current value for the iteration (e.g: if iterating the array ['a', 'b', 'c'], $forEachValue will first be equal to 'a', then 'b' and then 'c'), thus allowing the effect specified here to access the value of each element in the array one at a time. If you were to specify the optional for_each_value_key parameter, you should use the key given there instead of $forEachValue to access these values.
for_each_value_keyStringOptional parameter that lets you provide a key to use in the apply effect to access the array's current value in the iteration. e.g: if you are iterating classes, you might want to assign "$class" to the for_each_value_key, to make your system easier to read.
synchronousboolOptional parameter (true by default) to indicate if iteration should be done synchronously. If so, the app will wait until the apply function completes before continuing with the next value in the array. For example, if the apply function displays a pop up (by using the showPopUp effect), it will wait until the pop up is dismissed before carrying on with the next element in the array. Setting this to false will execute the apply effect for all values simultaneously.