How to Write a Roam Procedure in MicroWorld EX

By Camille McCue

You may encounter a scenario in MicroWorld EX where you would like your turtles to move around the screen. The roam procedure and Roam button put the turtles in motion and make them walk around the screen so that they have the opportunity to bump into each other and sometimes visit the hospital. Write a roam procedure and make an associated button as follows:

  1. On the project Procedures tab, type this procedure:

    image0.jpg

    to roam
    glide 50 0.5 rt random 360
    end

    The roam procedure instructs the turtles to move and turn so that they appear to be wandering around like real turtles. The command glide 50 0.5 tells each turtle to walk 50 pixels at a speed of 0.5, and the command rt random 360 tells each turtle to turn right by a random angle from 0 to 359 degrees.

    Adjust the glide distance and speed as well as the turn angle to create the motion you prefer.

  2. From the toolbar, click the Create a Button button and then click the workspace anywhere.

    image1.jpg

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

    • Label: Type Roam in the Label field to name the button.

    • Instruction: Type everyone [roam] in the Instruction field. This command instructs everyone, meaning all turtles in the workspace, to execute the commands inside the square brackets, specifically the roam procedure.

    • Do It: Select the Forever radio button.

    • Visible: Leave this check box selected.

      After you complete requested information in the Button dialog box your screen should resemble the following

      image2.jpg

  4. Click OK to close the Button dialog box.

    The Roam button is added to the workspace.

  5. Drag the button to reposition it to where you want it located.

    For example, place this button below another button, such as 1 Sick button in the upper-left corner of the workspace.

    When clicked, the Roam button instructs all turtles in the workspace to execute the roam procedure and to do so forever. Click the Roam button again to stop the Forever execution of the instruction.

    You can stop program execution at any time by clicking the Stop All button on the toolbar.

    image3.jpg