Actually I seem to have got it working now, it’s not ideal but I think it’ll do for the project I am working on.
Now when it looks at the value of the nearest keyframe, and it’s equal to the value it wants (in this case 10) it starts the 0-100 animation. When the nearest keyframe changes to something else, it looks at the previous keyframe to see whether it was the value it wanted (10) before firing the 100-0 animation.
This keeps all the expressions from firing the 100-0 animation before they are at 100.
There are still some issues, you need 2 keyframes at the start of the animation, I used frame -1 and -2, or else the the expression will attempt to evaluate a keyframe[0] and receive an error.
Also, if you try have 2 keyframes that are the same in a row, the second one restarts the animation back to 0-100 even though the value was already 100.
For this puppet rig I’m working on I don’t think it will cause any problems, but if anyone knows an easy solution for these problems I’m all ears.
sc = effect("123")("Slider");
sTime =.1;
sStart = 0;
sEnd = 100;
v=0;
oldv=0;
if (sc.numKeys > 0){
n = sc.nearestKey(time).index;
oldv=n;
if (sc.key(n).time > time) {
n--;
}
if (n > 0){
t = time -sc.key(n).time;
if (sc.value==10){
v = linear(t,0,sTime,sStart,sEnd);
}else{
if(sc.key(sc.nearestKey(time).index-1)==10){
v = linear(t,0,sTime,sEnd,sStart);
}
}
v;
}else{
value;
}
}else{
value;
}