<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 6/4/2014 9:19 AM, JOHNSON JULIE M.
wrote:<br>
</div>
<blockquote
cite="mid:cfb53094773643ad863b689902c45842@EXCAS2.williamsvillek12.net"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">How do you create and use a global variable
in Alice 3.1?<o:p></o:p></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader">Global variables are
discouraged by most software engineers, due to unwanted
side-effects that may occur when multiple programmers are
working on the same software application. However, there are
some cases in which a global variable is handy. One example is
in a game program where you are tracking things like score,
time, and end-of-game conditions. These conditions often need to
be checked and/or updated in several different methods. Alice 3
takes a "middle-of-the-road" stance on this issue. On the one
hand, Alice 3 discourages global variables by declaring
variables as (1) local to a specific method, or (2) private to a
specific class. However, the Scene class is (in a sense) global
in that all the objects are located all the action takes place
in a scene. You can take advantage of this by creating a
property variable in the Scene class. This variable is then
"global" to all procedures and functions defined in the Scene
class. As an example, in the first screen capture below, a
property variable is declared in the Scene class to track the <i>score</i>
of a game. In the second screen capture below, the updateScore
procedural method increases the score by 2. We could also write
other methods that access the score... for whatever purpose.<br>
</fieldset>
</blockquote>
<img alt="declare score variable"
src="cid:part1.04030502.01050707@andrew.cmu.edu" height="472"
width="358"><br>
<br>
<img alt="update the score"
src="cid:part2.03020902.09000109@andrew.cmu.edu" height="119"
width="398"><br>
<blockquote
cite="mid:cfb53094773643ad863b689902c45842@EXCAS2.williamsvillek12.net"
type="cite">
<fieldset class="mimeAttachmentHeader"> <br>
</fieldset>
<br>
<pre wrap="">_______________________________________________
alice-teachers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:alice-teachers@lists.andrew.cmu.edu">alice-teachers@lists.andrew.cmu.edu</a>
<a class="moz-txt-link-freetext" href="https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers">https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers</a>
</pre>
</blockquote>
<br>
</body>
</html>