What is the type of the $colorArray
variable? I suspect it was created as a Text variable, so the expression is ultimately getting implicitly serialized to a string.
You can also explicitly serialize and deserialize data to a string. If the variable type is Text, then values will implicitly be serialized to a string, but it will stay a string after being written to a Text variable. If you want to parse it back into array/object format for use within an expression, you must do that explicitly within the expression.
Serialize/Deserialize
Under the General String Manipulation section of the General Functions help article, you’ll find the functions stringify()
and parseJson()
which you can use to explicitly serialize and deserialize object data to/from a string.
So you could do something like the following if you want to explicitly serialize the data (though the implicit serialization may be fine for your needs):
- Set Variable
$colorArray
to expression:stringify([$colorHueBlue, $colorHueGreen, $colorHueOrange, $colorHueRed])
Or if you know the values you want in the array, just write it directly into the string as it sounds like the deserializing the data back to an array is the main part you need (eg. Set Variable $colorArray
to static value [71,33,11,0]
)
Then you could deserialize the string into an array and grab the item you want out of it:
- Set Variable
$colorHue
to expression:hues = jsonParse($colorArray) hues[ $cyclingCounter % 4 ]
This is using a trick that creates a hyper-local variable called hues
within the expression evaluation just to make it easier to reference things. Since your $colorArray will already have the value set, you should be able to Tap to Evaluate the expression and see the result to make sure your syntax is right.
Make sure your
$colorHue
variable is a Numeric type if you want to use it in commands that expect a numeric argument.
Random Value
If you wanted a random value from the array rather than to sequentially iterate through the colors, you could use the pickRandom([item1, item2, ... itemN])
function also documented in the help article linked above:
- Set Variable
$colorHue
to expression:pickRandom(parseJson($colorArray))