This lab assignment exercises will focus on the concept of a subprogram, sometimes referred to as a "control abstraction". In Alice the most common form of control abstraction is the procedure. By now you've used procedures many times in writing programs. The names of some of the procedures used are "move", "turn", "say", "setVehicle", and so forth. Each procedure is an operation that can be performed upon an Alice object. An instruction that causes the procedure to execute is referred to as a procedure call instruction. But someone had to write other instructions that we don't see for the procedure and these instructions execute in response to each call. Therefore, the name of the procedure serves as an abstract reference to the procedure's hidden instructions. This all means that an important skill for programmers is to write their own procedures. For this assignment you will build a procedure to make biped objects wave their right hand. To begin your project create a scene with a SEA_SURFACE, a pirate ship and any two bipeds you wish. Note that the pirate ship is too large, so please reduce its size to a width around 4.0 units. (The gray region to the right of the scene allows you to change properties like size.). Your scene should look something like the one shown to the right. Programming Steps 1) Begin with by creating two instructions that set each biped's vehicle to the pirate ship. 2) Now it's time to create a procedure to make define a new operation, we will call waveRightHand. To do this you first select Biped from the pull-‐down menu associated with each object's type. The picture to the right shows where to find this pull-‐down menu (circled). 3) At this time you should be viewing the image to the right: Now, under the blue procedures section click the Add Biped Procedure… button. Name your new procedure waveRightHand and you will see a screen that looks like you are writing a new program. This is because a procedure is largely an independent segment of code that is often called a "subprogram." For the next steps you will create the instructions for this procedure by dropping them in the area provided. 4) Alice allows access to every joint of its objects to be accessed and we need to use some joints in order to create the motion of an arm waving. To access the joints pull to the right of the this menu as shown to the right. Use this menu to select getRightShoulder. From the resulting menu you can insert a turn instruction. You want to create three instructions like this to begin your waveRightHand procedure. These instructions are as follows: getRightShoulder turn BACKWARD 0.35 getRightElbow turn BACKWARD 0.125 getRightShoulder roll LEFT 0.125 All of this is to raise an arm. 5) Now would be a good time to test this version of your procedure. To do so you should select the tab named myFirstMethod. Now, when you select either of your two Biped objects, you should find the waveRightHand method is an optional instruction (under Biped procedures). Insert two instructions into your program. One to call this wave method for each of the two Bipeds. When you run this program, you should observe each right hand raise. 6) The hand raising isn't very realistic, but can be improved somewhat by returning to your procedure and change the three instructions for the shoulder and elbow so that they are all placed within a single do together block. You will need to select the waveRightHand tab or the edit next to this method in order to make the changes. 7) Next you need to add instructions to this procedure to make the hand appear to wave. The following two instructions within a do together make a hand appear to wave in one direction: getRightWrist roll RIGHT 0.5 getRightWrist turn FORWARD 0.2 These instructions should be followed by two more to cause the hand to wave back in the opposite direction. Again, they look best if placed inside their own do together getRIghtWrist turn BACKWARD 0.2 getRightWrist roll LEFT 0.5 Again, you should try running your program to see how it works. 8) To create a completed method you need to cause the arms to lower by doing the reverse of the instructions that cause the arms to be raised. (You raised the arms from the instructions in Step 4.) 9) Procedures can be made more flexible in purpose through the use of parameters. You've used parameters, such as those to specify direction in a turn procedure or distance in a move procedure. We are going to add a parameter to allow the waveRightHand method to wave more than once before lowering the arm. You should begin by clicking the add Parameter … button just above the instructions for your waveRightHand procedure. Declare your parameter to be a WholeNumber and name it count. (Note you will be warned that you need to update the procedure calls in myFirstMethod. We will do this in Step 10.) You will need to use this variable and create a while instruction that repeats your wave instructions. The image to the right shows how your final procedure code should appear. 10) If you return to myFirstMethod, as you did earlier in Step 5, you should see that you can now specify some number of waves for each Biped. If time permits: You can try one or more of the following: make both Bipeds wave simultaneously create additional Bipeds and make them wave cause the pirate ship to move simultaneous with the waving (Hint set the distance and duration parameters both to 10.0.) use a while instruction in myFirstMethod in order to cause the wave procedure to be called 10 times consecutively. try to improve upon the hand waving to look more accurate.
© Copyright 2026 Paperzz