Affine Scheme of the form $X=Spec(R)$ for $R$ commutative ring, as the analogue of an affine variety $X$ with coordinate ring $R$ In this amazing notes http://www.mathematik.uni-kl.de/~gathmann/class/alggeom-2002/main.pdf pg.75 the author exlpains roughly the idea behind the notion of an affine variety and how does affiliate with that of an affine scheme. 
Now, my question has to do mostly with the remark 5.1.3 down from the definition of affine schemes. He says that for a given $f \in R$ we can see the latter as a function on $X$ in a standard sense, that is, for every $\mathcal{P} \in X$ we define $f(\mathcal{P})$ to be the value of the composition $R \rightarrow R/\mathcal{P} \rightarrow \mathbb{k}(\mathcal{P})$. That's exactly what I don't get. What kind of function is that? The values for any distinct $\mathcal{P} \in X$ has a different target. Can you please write me down explicitly what does he mean by that? I don't understand if for every $\mathcal{P} \in X$ we get something like a function $f_{\mathcal{P}}: R \rightarrow \mathbb{k}(\mathcal{P})$, or not. 
P.S. 
Excuse me if the latter isn't correct I'm just trying to get you what my problem is! 
 A: If $R$ is any ring then we can associate to any $f\in R$ a function
$$f:\text{Spec}(R)\to\bigsqcup_{\mathfrak{p}\in\text{Spec}(R)}k(\mathfrak{p})$$
where, of course,
$$k(\mathfrak{p})=R_\mathfrak{p}/\mathfrak{p}R_\mathfrak{p}$$
defined by 
$$f(\mathfrak{p})=\frac{f}{1}+\mathfrak{p}R_\mathfrak{p}\,``\text{=''}\,f\mod \mathfrak{p}$$
Note that for any two functions $f,g$ of this form we can 'add them' by declaring that $(f+g)(\mathfrak{p})$ is $f(\mathfrak{p})+g(\mathfrak{p})$ where the addition is happening in $k(\mathfrak{p})$ and multiply them in a similar way--this forms a ring. This is not shocking since 
$$\left\{f\in\text{Map}\left(\text{Spec}(R),\bigsqcup_{\mathfrak{p}\in\text{Spec}(R)}k(\mathfrak{p})\right):f(\mathfrak{p})\in k(\mathfrak{p})\right\}=\prod_{\mathfrak{p}\in\text{Spec}(R)}k(\mathfrak{p})$$
and the association of an element $f\in R$ to the function is just associating it to this tuple the tuple $(f\mod\mathfrak{p})$ and the addition is just this sum.
This then gives us a a ring map 
$$R\to \prod_{\mathfrak{p}\in\text{Spec}(R)}k(\mathfrak{p})\subseteq\text{Map}\left(\text{Spec}(R),\bigsqcup_{\mathfrak{p}\in\text{Spec}(R)}k(\mathfrak{p})\right)$$
which is, in general, not injective. Namely, the kernel of this map is $\text{Nil}(R)$ which contains precisely the nilpotent elements of $R$. Thus, in the case that $R$ is reduced we can faithfully think of $R$ as being a 'ring of functions on $\text{Spec}(R)$' where the functions are valued in this disjoint union space.
Here is an example of where one can clean this up a bit. Namely, let's assume that $R$ is reduced and finite type over a field $k$ (not necessarily algebraically closed). Then, for every maximal ideal $\mathfrak{m}\in\text{MaxSpec}(R)$ we know that $R/\mathfrak{m}$ is a finite extension of $k$. So, suppose that we've chosen an algebraic closure $\overline{k}$ and embeddings $k(\mathfrak{m})\hookrightarrow \overline{k}$ for all $\mathfrak{m}$. Then, we can associate to any $f\in R$ a function in
$$\left\{f\in\text{Map}\left(\text{MaxSpec}(R),\bigsqcup_{\mathfrak{m}\in\text{Spec}(R)}k(\mathfrak{m})\right):f(\mathfrak{m})\in k(\mathfrak{m})\right\} $$
which by similar ideas is a subset of 
$$\prod_{\mathfrak{m}\in\text{MaxSpec}(R)}k(\mathfrak{m})\hookrightarrow \prod_{\mathfrak{m}\in\text{MaxSpec}(R)}\overline{k}=\text{Map}(\text{MaxSpec}(R),\overline{k})$$
Thus, we get a ring map
$$R\to\text{Map}(\text{MaxSpec}(R),\overline{k})$$
which, in our case, is injective. This is the usual way one thinks about an element of $R$ as being a function on the variety $\text{MaxSpec}(R)$.
Hopefully this helps.
A: You are correct that this "function" lands in a different target for each point! Alex has given an answer which illustrates that you can make it an honest function. So the following answer is definitely more pedestrian.  
I will use the notation $\mathfrak{p}$ for a prime ideal of a ring $R$. In other words, $\mathfrak{p}$ is a point of $X=\text{Spec}(R)$. 
For example, when $R=\mathbb{C}[x]$  and $f=x+2$, let's try to evaluate $f$ at points of $X=\text{Spec}(R) = \mathbb{A}^{1}_{\mathbb{C}}$. We will evaluate the function in both variety sense (classically) and in a scheme sense. Maybe this will help clarify why the notions are basically the same.


*

*Classically, the function $f$ simply takes a point $a\in \mathbb{A}^{1}$ and adds $2$ to it, so we get an element $a+2\in\mathbb{C}$. 

*On the other hand, $\mathbb{C}[x]$ consists of the prime ideal (0) and maximal ideals $(x-a)$ for each $a\in \mathbb{C}$. The maximal ideal $(x-a)$ (which is a point of $X=\text{Spec}(R))$ corresponds to the point $a\in\mathbb{A}^{1}$ in the classical world. So what is the image of $f$ under the natural $R=\mathbb{C}[x]\to \text{Frac}(\mathbb{C[x]}/(x-a))$. Well, $\mathbb{C}[x]/(x-a) \cong \mathbb{C}$ via $x\mapsto a$ is already a field. Thus, our natural map becomes $\mathbb{C}[x]\to\mathbb{C}$ and so it sends $f(x)=x+2$ to $a+2$. Thus, on the closed points of $\text{Spec}(\mathbb{C}[x])$, we have described what the map is! It takes the maximal ideal $(x-a)$ to $a+2$. This exactly agrees with the description given in the previous bullet point, once you identify the maximal ideal $(x-a)$ with $a\in\mathbb{A}^{1}_{\mathbb{C}}$.

*Well, what about the generic point $(0)$? In other words, we haven't described where $f$ sends the prime ideal $(0)$. This is easy since $\text{Frac}(R/(0))=\text{Frac}(R)=\text{Frac}(\mathbb{C}[x])= \mathbb{C}(x)$, the field of rational functions in $x$. So, the map we are interested in is the inclusion $\mathbb{C}[x]\hookrightarrow \mathbb{C}(x)$, and the image of $f$ under this map is just $f$ again. 

