If $(X, \mathcal O_X)$ is a scheme, what is $\mathcal O_X(U)$ where $U$ is any open subset (not necessarily affine open)?
Below is what I currently know.
Let $A$ be a ring.
Hartshorne defines the structure sheaf on $\operatorname{Spec}(A)$ as:
For an open subset $U \subset \operatorname{Spec}(A)$, we define $\mathcal O(U)$ to be the set of functions $s: U \to \coprod_{\mathfrak p \in U} A_{\mathfrak p}$, such that:
i.) $s(\mathfrak p) \in A_{\mathfrak p}$
ii.) for each $\mathfrak{p} \in U$, there is a neighborhood $V$ of $\mathfrak p$, contained in $U$, and elements $a, f \in A$ such that for each $\mathfrak q \in V$, we have $f \notin \mathfrak q$ and $s(\mathfrak q) = a/f \in A_{\mathfrak q}$.
Vakil first defines a sheaf of rings on the distinguished base $D(f) \subset \operatorname{Spec}(A)$:
Define $\mathcal O_{\operatorname{Spec} A}(D(f))$ to be the localization of $A$ at the multiplicative $\{g \in A \mid D(f) \subset D(g)\}$.
An exercise shows that $\mathcal O_{\operatorname{Spec} A}(D(f)) \cong A_f$, and that the stalk of at a point $\mathfrak p$ is $A_\mathfrak p$.
Since we have a sheaf on a base, we can extend this to all open $U \subset \operatorname{Spec} A$
Define $\mathcal O_{\operatorname{Spec} A}(U)$ to be the set of all $(s_{\mathfrak p})_{\mathfrak p \in U} \in \prod_{\mathfrak p \in U} A_\mathfrak p$ such that
i.) $s_\mathfrak p \in A_{\mathfrak p}$
ii.) for each $\mathfrak{p} \in U$, there is a neighborhood $D(f)$ of $\mathfrak p$, contained in $U$, and an element $a \in A$ such that for each $\mathfrak q \in D(f)$, we have $s_\mathfrak q = a/f^n \in A_{\mathfrak q}$.
I can see how the two definitions are related: given a function $s \in \mathcal O(U)$ as in Hartshorne, we get $(s(\mathfrak p))_{\mathfrak p \in U} \in \prod_{\mathfrak p \in U} A_\mathfrak p$ as in Vakil. The converse is similar.
Both authors define:
A scheme $(X,\mathcal O_X)$ is a ringed space such that any point of $X$ has an open neighborhood $U$ such that $(U, \mathcal O_X|_U)$ is isomorphic to an affine scheme.
I am confused about functions on a scheme $(X,\mathcal O_X)$.
It seems Hartshorne is explicitly defining what functions on an affine scheme should be in his definition, but not what functions on an arbitrary scheme should be. Why?
Vakil writes: Functions on an open subset $U$ of a locally ringed space have values at each point of $U$. The value at $p\in X$ of such a function lies in $\mathcal O_{X,p}/ \mathfrak m_p$ where $\mathfrak m_p$ is the maximal ideal of $\mathcal O_{X,p}$.