[This is an intuitive answer. I expect and would welcome corrections by members with real knowledge of set theory.]
The wikipedia entry addresses these issues. Sometimes, though, an initial push comes really handy. In this regard, it is possible that you are thinking of functions more in the way of a polynomial or a transcendental function, such as $f(x) = 3x$ or $f(x) = \frac{1}{sin(x)}$. This is not the sense in which the term is used in the definition of a random variable, where function is more of a mapping or correspondence between the result of a random experiment (i.e. whatever process - tossing a coin, dice, counting successes, etc. - which cannot be predicted a priori), which is referred to "outcome", and the real line $\left(\mathbb{R}\right)$.
I imagine $X$ in the OP as the $f(\cdot)$ symbol, which can take any values of $x$ in $f(x)$ to produce a $y$, where most commonly both $x$ and $y$ are going to be real valued. Here, though, the input is not a numeric value, but rather an outcome of the experiment to which we will assign a number (different from its probability). The process of assigning the number is the function we are referring to. Your $X(w)$ is the actualization of the random variable, much like $f(x=7) = x^2 =49$. In your case $w$ represents a given outcome in the sample space.
The experiment may consist in throwing two dice, a very concrete thing in the real world. Yet, if we want to start constructing a probability space, we'll need to define exactly what we are interested in recording, and how we measure it.
Commonly we'll pay attention to the side pointing up, but not necessarily. We could instead record the distance between both dice; or the number of tumbles they take before they settle. Each one of these "takes" on the experiment will define the sample space $\left(\Omega\right)$ with all its possible outcomes.
The random variable as a function will determine how these outcomes are measured. For instance, we may define it as the sum of the sides pointing up, or else the multiplication of the sides. If what we pay attention as outcomes in the sample space are distances, we can measure the distances to a reference point, or in between the dice, in inches or centimeters, etc. These are the decisions that define the random variable as a function.
So $X(w)$ is the random variable as it applies to the outcome $w$. And presumably if $w\not\in \Omega$, $X$ will not be defined. And if the preceding is correct, then the difference between a discrete random variable and a continuous is already addressed in connection to the way we measure the outcomes.