Sorry I didn’t think it through: You can’t keyframe a layer control. So it would be a combination of Dan’s method of turning the slider value to a selector plus getting the x position of said layer.
You can simplify the matter by leaving out the leading zero so that the layer name is TITLE_1, TITLE_2, etc.
Thus, the code for ball position based on a slider would be:
pos = transform.position;
num_layers = 3; // highest layer number
layer_num = Math.floor(effect("Slider Control")("Slider"));
target_layer= "TITLE_"+layer_num;
if (layer_num>0 & layer_num<=num_layers) {
x=thisComp.layer(target_layer).transform.position[0];
new_position = [x,pos[1],pos[2]]
} else {
pos}
Dan would write it much neater, though 🙂