Hi Nick, you’re correct the setup now only seems to catch 1 positive and 1 negative term.
I would approach it a bit differently:
- remove the separate red and green animators (but keep the expressions of the sourceText)
- make the text Black in the Character palette
- add a textanimator that colors the RGB Fill of the letters White.
- give this text animator an expressions selector, make sure to set it “based on words”
- here’s the expression, by “partially” selecting the amount the black letters become white, we can actually color it in. The resulting value of an expression selector can actually have up to three dimensions, and in this case that corresponds to RGB.
words=text.sourceText.trim().split(/\s+/);
i=textIndex-1;
if (words[i].match(/-[0-9\.]+%/)!==null) {
[100,0,0]; // red
} else if (words[i].match(/\+[0-9\.]+%/)!==null) {
[0,100,0]; // green
} else {
[100,100,100]; // white
}
This way you can set up even more regexp matches, for example:
… } else if (words[i].match(/[0-9\.,]+€/)!==null) {
[80,70,0]; // yellow
} else { …