arameters and variables only exist inside their own functions. Within
the confines of
, there is no such thing as
. If you try to use it, the compiler will complain. Similarly, inside
there is no such thing as
. Variables like this are said to be local
. In order to keep track of parameters and local variables, it is useful
to draw a stack diagram. Like state diagrams, stack diagrams show the
value of each variable, but the variables are contained in larger boxes
that indicate which function they belong to.
For example, the state
diagram for ShowTextTwice looks like this:
Whenever a function is
called, it creates a new instance of that function. Each instance of a
function contains the parameters and local variables for that function.
In the diagram an instance of a function is represented by a box with
the name of the function on the outside and the variables and
In the example, Scene1 has
one local variable, sWarning, and no parameters. ShowTextTwice has no
local variables and one parameter, named sMessage.