These discussion questions concern the PaintPot tutorial, chapter 2 of the App Inventor book. Concepts include event-handlers, event parameters (arguments), and variables. For related reading, see chapter 2, 14 (app architecture) and 16 (an app's memory).
1. Draw the event-handlers that are involved with lines being drawn a particular color.
There are three event handlers related to the user clicking a button to change the line color (PaintColor). An example is:
DrawingCanvas.PaintColor -> red
There is another event-handler which handles the user dragging to actually draw the lines:
when DrawingCanvas.Dragged startx, starty, prevx, prevy, currentx, currenty
DrawLine draws in the color that is stored in the PaintColor property. So the three button events change a memory cell (the DrawingCanvas.PaintColor property) and the DrawLine function in the Dragged event looks at the property to know what color to draw.
2. Draw the event-handlers that are involved with the dots being drawn big or small.
This question is similar to the above one. In this case, the user clicks on the BigButton or SmallButton. But there is no property for "dotsize" in DrawingCanvas. Thus a variable, named dotsize, must be defined to store the 2 or the 8 (the specified sizes). The Touched event then uses the value in the dotsize variable as the radius:
set dotsize to 8
when DrawingCanvas.Touched x,y
DrawingCanvas.DrawCircle(x,y, radius = dotsize)
So the variable dotsize stores the number and the function DrawCircle uses it for its radius.
3. In PaintPot, there are parameters for some events. How are event parameters different than the parameters that are part of a call to a function (e.g., Sound.Vibrate (500) ? Who sets the value of the parameter?
Event parameters provide the information about the event. They are not set by the program, but by the system. So when the user touches the screen, the Touched event has three event parameters, x,y, and touchedSprite. The programmer can use those values, but the programmer doesn't set them, as she does with function parameters.
Function parameters provide the information a function needs to do its job. The programmer specifies this information in the call to the function, e.g, in the call to DrawCircle, the programmer specifies the location (x,y) and the radius (dotsize).
4. In PaintPot you define a variable.