-
How would I get the nth number from a number sequence?
Hi smarter people than I…..
I’m sure I am over thinking this and that there is a simple solution to my problem.
So, I have, for example, 100 layers, each layer with an index from 1 to 100. What I would like to do is execute an expression on each layer depending on if the layer is the nth (or in my case every 3rd) layer in the sequence. i.e the expression executes if the layer is the 3rd, 6th, 9th, 12th etc…
I’d wrap this in an if() statement so it would return as true if the layer had an index of 3, 6, 9, 12 and so on.
The way I am doing it currently is below:
if(idObjectIndex == 3 || idObjectIndex == 6 || idObjectIndex == 9 || idObjectIndex == 12 || idObjectIndex == 15 || idObjectIndex == 21) {
idControlColours[0];Obviously doing it this way is very long winded, inefficient and not dynamic if I were to add more layers beyond the what I have already setup.
Getting either 1st or 2nd layer in the sequence I can do by evaluating if it is either odd or even:
idObjectIndex % 2
Which is straight forward enough but where I come unstuck is getting the 3rd, 4th or even the 5th layer in the sequence.
I’m sure there is a simple way to do this and my scouring of the inter-webs has just made things more confusing… or maybe I am asking the wrong questions.
Any pointers would be great!
Standing by to slap my forehead and say “doh, of course, how obvious !”
Many thanks!
P.