How to Write a Reset Procedure in MicroWorld EX

By Camille McCue

A reset procedure in MicroWorld EX will restart the program to its initial settings. For a racing UFO in space code it would set the initial value of the score to zero and places the UFO at its starting position in the center of the workspace.

Create a reset procedure as follows:

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

    image0.jpg

  2. Type the following reset procedure:

to reset
setscore 0
ufo, home
end

Here’s how the reset procedure works:

  • First, it sets the initial value of the score (setscore) to 0.

  • Second, it gives the ufo the home command. home is a primitive that sets the position of a turtle to the coordinates (0, 0) and sets its heading to 0, pointing north.

During the game, you will change the heading of the ufo, so don’t worry about its heading right now. The shape of the UFO appears to be facing east, although the heading of its turtle will always be either north (seth 0) or south (seth 180).

Also, if desired, you can set the starting position of every asteroid cluster, although this is not necessary.

In a side-scrolling game, the main character never actually moves side-to-side — it only moves up and down (north and south). The other objects in the game move from side to side, creating the appearance that the main character is actually moving horizontally, even though it isn’t.

After you have written the reset procedure, MicroWorlds EX recognizes it as a new command that you can use. Create a button to run the procedure by following these steps:

image1.jpg

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

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

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

    • Instruction: Type reset in the Instruction field.

    • Do It: Select the Once radio button.

    • Visible: Select this check box so the button is visible.

      image2.jpg

  3. Click OK to close the Button dialog box.

    The Reset 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 Reset button to makes sure it functions as expected.