Skip to main content
Known Participant
May 24, 2022
Answered

Selecting specific textIndex

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

 

 

Known Participant
July 3, 2022

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.


Thank you, Dan, for your time,

I am not sure if I was clear enough in my question.

 

Just to explain something in general, I am building the box chart graphic using Webdings "g" letter which is a square (you can see the reference image in the attachment above)

 

Let's say I have a box graph with 4 rows and 5 columns

 

With the expression that I used based on your previous advice, it selects 1st box and then 5th, 9th, 13th and 17th.

 

My question is how can I write the expressions that select 1st 4 boxes.

And because I am using thisProperty.propertyGroup(3).name but duplicating the "Animator"

I should be able to select 5th to 8th and then 9th to 12th and so on.

 

This may be very basic and I thank you again for your help.