Skip to main content
Known Participant
May 24, 2022
Answered

Selecting specific textIndex

  • May 24, 2022
  • 2 replies
  • 4020 views

Hello,

how do I simplify and optimize the code below? As you can see I would like to affect every 6th character starting with #2 when the length of the text is not predetermined. Thank you in advance.

 

if(textIndex == 2 || textIndex === 8 || textIndex === 14 || textIndex === 20 || textIndex === 26) {

     100;

} else {

     0;

}

This topic has been closed for replies.
Correct answer Dan Ebberts

Dan,

apologizes for taking more of your time for such basic questions,
but what is the best way to combine

 

textIndex%6 == 2 ? 100 : 0

and

textIndex%6 == 0 ? 100 : 0

so one expression will cover both of these situations.

I am asking all of this because I am taking  #2 from 

 

thisProperty.propertyGroup(3).name;

 

where "Animator" name is "2".

Of course, I start with "1" and by duplicating the animator everything works fine until I hit the 6th copy. As you recommended I could change it manually into "0" but I am looking for the way that the original expression applied to the "1" will work in the "6" etc., as well.
Thank you in advance.


Like this I guess:

n = thisProperty.propertyGroup(3).name%6;
textIndex%6 == n ? 100 : 0

2 replies

Mylenium
Legend
May 24, 2022

Here's another solution:

 

gLen=6;
gOff=2;

((textIndex+gOff) % gLen)*selectorValue

 

Mylenium

Known Participant
May 24, 2022

Thank you Mylenium. That is interesting but it gives different results than what I was looking for. It applies color to 1-3 skips 4 and then applies to 5-6. Check the attached if curious.

Mylenium
Legend
May 24, 2022

textIndex % 6 + 2

 

Mylenium

Known Participant
May 24, 2022

Thank you.

When I replace 

(textIndex == 2 || textIndex === 8 || textIndex === 14 || textIndex === 20 || textIndex === 26)

with

(textIndex % 6 + 2)

the effect is not the same.

Attached is the screenshot of what I am trying to achieve and it is working with my expression, but I would just like to simplify it so I can automate different scenarios. 

 

 

Dan Ebberts
Community Expert
Community Expert
July 3, 2022

Hi,

one additional question. Dan's solution from above works perfectly for selecting rows. I would like an added checkbox to be able to switch from selecting from rows to columns. The only way right now I can do it with the expression below but I have to manually switch Expression selector>Based On from Characters which will give me row selection to LINES which will select columns.

 

row = effect("ROWS")("Slider");

column = effect("COLUMNS")("Slider");

checkN = effect("if OFF vertical COLORS --- if ON horizonatal COLORS")("Checkbox");

 

numb = (checkN == 0) ? row : column;

 

numToColor = thisProperty.propertyGroup(3).name%numb;

 

textIndex%numb == numToColor ? 100 : 0

 

Is there any way to add expressions to select 1st, 2nd, etc columns so I avoid manually switching Expression selector?

A few screenshots are included one is with what happens with the character selected, one is with lines selected, and one is a screenshot of the expression's timeline section just for reference.

As always thank you so much.


I think your setup is the opposite of what I'm used to, but when I've done grids in the past, you get the column number with index%numberOfColumns and you get the row number with Math.floor(index/numberOfColumns). I don't know if that helps at all.