TITLE: When are the sections of the structure sheaf just morphisms to affine space?
QUESTION [7 upvotes]: Let $X$ be a scheme over a field $K$ and $f\in\mathscr O_X(U)$ for some (say, affine) open $U\subseteq X$. For a $K$-rational point $P$, I can denote by $f(P)$ the image of $f$ under the map
$$\mathscr O_X(U) \to \mathscr O_{X,P} \twoheadrightarrow \mathscr O_{X,P}/\mathfrak m_P = K.$$
This yields a map $f:U(K)\to K$. Giving $U$ the induced subscheme structure, when does this uniquely define a morphism $f:U\to\mathbb A_K^1$ of schemes? It certainly works when $X$ is a variety (and $K$ algebraically closed), so there should be some "minimal" set of conditions for this interpretation to make sense. Thanks a lot in advance!

REPLY [3 votes]: The scheme $\mathrm{Spec}(k[X])=\mathbf{A}_k^1$ is the universal locally ringed space with a morphism to $\mathrm{Spec}(k)$ and a global section (namely $X$). What I mean by this is that for any locally ringed space $X$ with a morphism to $\mathrm{Spec}(k)$ (equivalently $\mathscr{O}_X(X)$) is a $k$-algebra) and any global section $s\in\mathscr{O}_X(X)$, there is a unique morphism of locally ringed $k$-spaces $X\rightarrow\mathbf{A}_k^1$ such that $X\mapsto s$ under the pullback map $f^*:k[X]=\mathscr{O}_{\mathbf{A}_k^1}(\mathbf{A}_k^1)\rightarrow\mathscr{O}_X(X)$. This is a special case of my answer here: on the adjointness of the global section functor and the Spec functor