Help with arrays

so, kinda stupid question, but how do i get a random child from an array, and then display its contents. the code needs to get a random child and then display its value as a text object.

You can:

  1. Use a random index

  2. Use the Array Tools extension, shuffle the array and select the first element

@MrMen I noticed one small issue with the 1st method.

The expression in the 1st action should actually be:
Random(VariableChildCount(MyArray) - 1)

If let’s say the array has 5 children, then the last child index would be 4.
But the expression Random(5) would sometimes result in 5, which will select a child index that doesn’t exist in the array.

Ah, yes, in my haste I omitted to subtract 1 from the length. Thanks for picking that up.

1 Like