This lesson plan came in July '98 from a FutureKids teacher in the Philippines It's just terrific! Give it a try and let us know how it goes. And if you have any great lesson plans of your own, send them to us (fm@kartoffelsoft.com) and we'll post them here in the CPU.
Subject: Modularizing the Program: Received Boxes and Passing Data to Sub-Task Parameters
Hi Janet,
Heres something you can share with other FUNdaMENTAL teachers.
Ive found that students understand the concept of reusable code nicely when we discuss sub-tasks that use received boxes.
To help them appreciate reusable code, I ask them to write a sub-task which is a fixed loop that moves an object certain increments in the x and y directions a given number of times.
1. We go to the Program Window, click new and name the sub-task mover. 2. We name four received boxes: some_object, times, xdist, and ydist in that order.. 3. We then write the following code in the mover Task Window: SET LOOP times @move LOAD BOX some_object MOVE OBJECT xdist, ydist JUMP LOOP @move
END SUB-TASK
4. We design a mermaid object and initialize it with a picture, such as mermlt.bmp. 5. In the main window, we construct the mermaid object, place it, show it and store it in a box as global variable mermaid. The initial code would look something like this: INSTALL BACKGROUND underwtr.bmp RESIZE PLAYGROUND 700, 350
CONSTRUCT OBJECT mermaid PLACE OBJECT 720, 200 SHOW OBJECT STORE BOX mermaid
6. Say we want to move the mermaid from outside the playground to about the middle of the background in increments of 5 pixels. The kids figure that they will need a loop that executes MOVE OBJECT with an x value of -5 and a y value of 0 about 70 times. We then call the sub-task mover and specify the values of the parameters. The students type EXECUTE SUB-TASK and, in the Data Wizard, choose mover. They then specify that some_object should be mermaid, times should be 70, xdist -5 and ydist 0. The rest of the code would be:
EXECUTE SUB-TASK mover (mermaid, 70, -5, 0) EXIT PROGRAM
7. They then experiment with changing the literal values passed to the times, xdist and ydist parameters to see how the object behaves.
8. They then create a second object, say a fish, initializing it with fishrt.bmp, and add the code: CONSTRUCT OBJECT fish PLACE OBJECT -20, 200 SHOW OBJECT STORE BOX fish
9. We then decide that the fish should from outside the playground on the left to about the middle of the background in increments of 5 pixels. The students figure that they will need a loop that executes MOVE OBJECT with an x value of 5 and a y value of 0 about 50 times so it does not overlap the mermaid. They then call the sub-task mover and specify the values of the parameters. The additional code looks like this:
EXECUTE SUB-TASK mover (fish, 50, 5, 0)
10. This exercise shows them that the code can be reused for any object within the program.
11. Next we create a new FUNDAMENTAL program and add the mover sub-task from the first program and the kids are delighted to see that the code works just as well in the new program.
12. Finally, we try a program in which we pass variables rather than constants to the sub-task parameters. This really opens their eyes to the potential of sub-tasks that receive data.
Note: All the graphics referred to in this exercise are found in the FUNdaMENTAL CD. They can be found with the Find utility on the Start menu of Win 95.
Jed Natividad Futurekids Philippines
|