How to Write a Startup Procedure in MicroWorlds EX
A startup procedure is a procedure that runs automatically as soon as you open a MicroWorlds EX project. The name startup is reserved for this purpose only. Write a startup procedure for the voting machine as follows:
Click the project Procedures tab (located in the lower-right corner of the window).
Type the startup procedure as follows:
to startup everyone [setsize 20] end
This startup procedure sets the initial size of all turtle candidates to 20. Because size is a variable, it can have different values as votes are cast for a candidate. Each turtle candidate has its own size variable, and each turtle’s size can be changed independently.
Because the size variable is an attribute possessed by every turtle, you don’t have to create this variable. In other projects, you will learn methods for creating new variables.
Type startup in the Command Center to execute the startup procedure and determine whether it works the way you want.
All candidate turtles should set their size to 20. Because their default size was 40, the turtles should appear to shrink in the workspace.
You can tinker with the value of size until you find a good starting value for your machine. The minimum value of size is 5, and the maximum value is 160.
You may have heard of the term variable in a math class. Variables are quantities that can have different values at different times. In MicroWorlds EX, size is a built-in variable possessed by every turtle. Size can start out as one value and then change to a different value at a later time.
Variables can increase or decrease in value according to instructions provided by the code you create. By contrast, constants are numbers such as –9 or 0.102003. Constants never change in value.