Dan you are an absolute genius. In the last hour some deep subconscious part of my brain was able to understand your previous expression enough to edit it to make it work for my purposes. I would still love an untangling of the time%period part but in the meantime I’ll explain my situation and resulting solution:
I am making a short film where my hair and clothes change every frame of the video. In some scenes there are as few as 8 takes to cycle through and in others closer to 14. To achieve this I’ve put an expression on every layer that says to only be visible when it’s index matches the number on a slider called “layer selector”. Previously I had been animating that “layer selector with keyframes but it became increasingly frustrating when I wanted to adapt to different numbers of layers and still have the layers show equally long. This became even more frustrating when I wanted to experiment with the video frame rate. In any case the following was bashed together with trial and error and as I said probably some unconscious understanding. It works fabulously. Not only do I only have to enter the start and end layer to cycle through but now it shows each layer for exactly the right number of frames given the frame rate I’m choosing through the posterize time effect. In this case it cycles through layers 2-8 changing every 3 frames because my comp is 30fps and my posterize time is at 10fps.
var startlayer = 2;
var endlayer = 8;
var compframerate = 1/thisComp.frameDuration;
var numberoflayers = endlayer-startlayer;
var period = (numberoflayers+1)*(compframerate/effect(“Posterize Time”)(“Frame Rate”));
var t = timeToFrames(time)%period;