An open connected set in is path-connected. Given two points with a continuous path connecting them, you can split the path into segments each of which lies in a convex subset of S (e.g. an open ball contained in S). So f will be independent of on each segment, and therefore along the whole path.