How to Code Selection Procedures for the Drop-Down Lists in MicroWorld EX

By Camille McCue

A procedure and button allow the MicroWorld EX user to apply a monster part choice made from a drop-down list. These procedures are selecthair, selectface, selectbody, and selectfeet. You will write each procedure and then make a button to execute the procedure. Follow these steps:

  1. Open the project Procedures pane.

    image0.jpg

  2. Type the following selecthair procedure:

    to selecthair
    if hairdrop = 1 [hairturtle, setsh "greenhair]
    if hairdrop = 2 [hairturtle, setsh "goldhair]
    if hairdrop = 3 [hairturtle, setsh "bluehair]
    if hairdrop = 4 [hairturtle, setsh "orangehair]
    end

    Here’s how the procedure works:

    • If the first shape, greenhair, in the Hair drop-down list is selected (if hairdrop = 1), the greenhair shape is applied to the hairturtle.

    • If the second shape, goldhair, in the Hair drop-down list is selected (if hairdrop = 2), the goldhair shape is applied to the hairturtle.

    • If the third shape, bluehair, in the Hair drop-down list is selected (if hairdrop = 3), the bluehair shape is applied to the hairturtle.

    • If the fourth shape, orangehair, in the Hair drop-down list is selected (if hairdrop = 4), the orangehair shape is applied to the hairturtle.

    An if-then conditional is written for each shape in the drop-down list. There are four hair shapes in the hairdrop, so there are four conditionals in the selecthair procedure.

  3. Next, you need to create a button that executes the selecthair procedure. On the toolbar, click the Create a Button button.

    image1.jpg

  4. In the Button dialog box, fill in the following information:

    • Label: Type the name of the body part (Hair, for example) in the Label field.

    • Instruction: Type the name of the procedure that puts the selected shape on the monster (for example, selecthair).

    • Do It: Select the Once radio button.

    • Visible: Leave this check box selected.

      image2.jpg

    The completed dialog box for the example.

  5. Click OK to close the Button dialog box.

    The Hair button is added to the workspace of the toy.

  6. Drag the button to position it next to its drop-down list.

    When the player clicks the Hair button, the selecthair procedure is executed. The hair shape selected at the hairlist drop-down list is applied to the hairturtle.

  7. Follow the same pattern in Step 2 to create procedures for selectface, selectbody, and selectfeet.

    Here is the code for the selectface procedure:

    to selectface
    if facedrop = 1 [faceturtle, setsh "happyface]
    if facedrop = 2 [faceturtle, setsh "madface]
    if facedrop = 3 [faceturtle, setsh "worryface]
    if facedrop = 4 [faceturtle, setsh "sadface]
    end

    Here is the code for the selectbody procedure:

    to selectbody
    if bodydrop = 1 [bodyturtle, setsh "orangebody]
    if bodydrop = 2 [bodyturtle, setsh "greenbody]
    if bodydrop = 3 [bodyturtle, setsh "bluebody]
    if bodydrop = 4 [bodyturtle, setsh "pinkbody]
    end

    Here is the code for the selectfeet procedure:

    image3.jpg

    to selectfeet
    if feetdrop = 1 [feetturtle, setsh "creepyfeet]
    if feetdrop = 2 [feetturtle, setsh "slipperfeet]
    if feetdrop = 3 [feetturtle, setsh "birdfeet]
    if feetdrop = 4 [feetturtle, setsh "duckfeet]
    end
  8. Follow the same pattern in Steps 3–6 to create buttons to execute the procedures for the selectface, selectbody, and selectfeet procedures that you created in Step 7.

    Here is a complete list of all objects and instructions you create for Monster Mashup:

    Turtle Name Drop-Down List Name Drop-Down List Labels Button Name Button Instruction (Selection Procedure)
    hairturtle hairdrop greenhair, goldhair, bluehair, orangehair Hair selecthair
    faceturtle facedrop happyface, madface, worryface, sadface Face selectface
    bodyturtle bodydrop orangebody, greenbody, bluebody,
    pinkbody
    Body selectbody
    feetturtle feetdrop creepyfeet, slipperfeet, birdfeet, duckfeet Feet selectfeet

The example shows four options for each body part, but you can use more or fewer parts. Just be sure to adjust your drop-down lists and selection procedures to match the number of shapes you create for each part.

Carefully match the order of shapes in the drop-down list with the order of shapes in the selection procedure. Also, be cautious to match the spelling of the shape name to its spelling in the procedure to minimize errors and reduce troubleshooting time.

Conditional statements, including the IF-THEN commands used in Monster Mashup are critical to any toy or game you code. See Projects 7 and 8 for additional details on working with IF-THEN commands.