MicroWorlds EX™ Lessons

Lesson Seven: Variables

In creating a cool project, you surely don't want to have the same old stuff moving along in a predictable way. In MicroWorlds EX, you can choose from a variety of ways to change things up:


Random Values

One easy way to add a little chaos to your project is to use the Random # command whenever a number is need in MicroWorlds. Some possible uses are given in the chart below:

Replace This Command
With This New Command
fd 100 (send turtle forward exactly 100 steps)
fd random 200 (sends turtle forward a random # of steps between 0 and 199)
setbg 95 (sets background to an exact shade of blue)
setbg 90 + random 10 (sets background to a random color in the blue range)
Repeat 20 [ fd 5 wait 1] (sends the turtle forward exactly 5 steps 20 cycles in a row)
Repeat 20 [ fd random 10 wait 1] (sends the turtle forward a random number from 0 - 9 for 20 cycles with a different number chosen each time) (This makes for a more exciting race.)

Sliders

Sometimes though, chaos isn't what you are looking to create. With Sliders, you can define a range of values for the variable, and let the user make choices within that range. Start with the Slider icon . . on the top grey toolbar and then the dialog box at the right pops up. You can change the name of the slider, the current value and the minimum or maximum values for this new variable.

You can change the value of this slider with a command: setslider1 57 to set the current value of slider1 to 57, or setslider1 slider1 + 5 to set the current value of slider1 to 5 higher than whatever value it has right now.


Variables (using commands and names only)

The easiest way to get started is to create a slider and then rename it to "length" or "speed" or any other term you want to use as a variable. For example, I started by creating a slider and then in the dialog box that opened up (see the image on the right side of the table just above) I changed the name to "length" and made the minimum value 10 and maximum value 100 with a starting value of 55. I also exercised the option to make it a vertical slider and left it visible, with the name showing. If you want to use a variable but not open it up to the person who tests out your project, just set up the slider the way you want it, and then click off the check box for "visible".

You can also use this type of variable to gradually increase or decrease the value of the variable. To do this, just use a sequence like this one:

OR complete this all in one more complex command:

setlength 20 repeat 7 [repeat 4 [ fd length rt 90 ] setlength length + 5]

Note: If your slider variable is named "Speed", the command to set the speed variable to a level of 37 would be:

setspeed 37

To reduce the speed variable by 14 units from its current value, type in:

setspeed speed - 14


Lesson Eight: Print and Announce Commands & Textbox Tips

Main MicroWorlds EX Tips Page



HTS Home | Calendar | Classes | Departments | Resources | What's New? Newsletter
©2008 Holy Trinity School HTS HomeContact HTS