Skip to main content
Known Participant
May 24, 2022
Answered

Selecting specific textIndex

  • May 24, 2022
  • 2 replies
  • 3970 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
Brainiac
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
Brainiac
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. 

 

 

Known Participant
May 25, 2022

Thank you.


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.