Basics of MicroWorld EX’s Go Procedure

By Camille McCue

Your MicroWorld EX game will use a go procedure to start the game action. Write the go procedure and then make an associated Go button. Follow these steps to write the go procedure:

How to write a MicroWorld EX Go procedure

  1. Click the project Procedures tab (located in the lower-right corner of the window).

    image0.jpg

  2. Type the following go procedure:

to go
everyone [setx random 740 clickon]
tto [squid shark] st
ink, ht
end

The go procedure instructs everyone— in this program example the squid turtle, the ink turtle, and the shark turtle — to set its x-coordinate to a random number up to 740, which is the width of the workspace. This has the effect of placing the turtles in random positions horizontally across the screen, with the objective being to separate the squid from the shark at the start of the game.

The clickon portion of the everyone command then clicks on all three turtles. You will write instructions in the OnClick fields of each turtle so that they know what commands to perform when clicked on.

The procedure then talks to (tto) the squid and shark, instructing them to show turtle (st).

The command ink, ht tells the ink turtle to hide because the squid hasn’t shot the ink cloud at the shark — yet!

As an additional challenge, add a line of code to the go procedure to disperse the objects vertically as well. This helps further separate the squid and shark. Using only horizontal separation, there will be occasions when the shark and squid end up touching each other at the start of the game. Using both horizontal and vertical random positioning helps reduce the chance of an initial collision.

How to create a Go button in MicroWorld EX

After you have written the go procedure, MicroWorlds EX recognizes it as a new command that you can use. Follow these steps to create a Go button to run the procedure:

  1. On the toolbar, click the Create a Button button. Then click anywhere on the workspace.

    image1.jpg

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

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

    • Instruction: Type go in the Instruction field.

    • Do It: Select the Once radio button.

    • Visible: Select this check box to leave the button visible.

    The completed dialog box:

    image2.jpg

  3. Click OK to close the Button dialog box.

    The Go button is added to the workspace.

  4. Drag the button to an out-of-the-way position in a corner of the workspace.

  5. Test the Go button to make sure it functions as expected. Note that the ink turtle should disappear because it is given the hide turtle command.