Material array variable acting funny

I’m not entirely sure how to ask this question because of all the strange behavior I’m getting, but I’ll try to sum it up. basically, I have this graph code:

which is meant to change the material on an object based on the array and the integer “current_page”, however I’m getting a bunch of weird behavior.

if I set current_page to 0 in the inspector, it stays on 0 while the materials keep changing. if I set it to 1 first then the integer acts correctly being added and subtracted when it should, however the material array doesn’t really correspond to the array. 0 isn’t the material in 0, and it just cycles between material 1 and 2 over and over. if that makes sense.

if it helps any, I also have this second button which is essentially a copy of the first but in the negative direction.

this is how I know it’s cycling even though there’s only 3 values in my array. the variable will go
[0,1,2,1,0,1] but the actual materials on the object will cycle through the array like [0,1,2,1,2,1,2]

hopefully that’s a good enough explanation; please help, I’m completely baffled by this.

figured it out. the problem was twofold, basically. using a block and a branch was the wrong move.
I have to set it so the math happens first in the sequence instead of at the same time, like this:

after setting it up so it flows right, everything works correctly, because now it’s comparing the correct values, instead of going over what’s available in the array and locking up after going below 0 or above 3.