A procedure is a list of instructions with a name. Primitives and procedures are the words that your project and the objects in it know how to do. Once you've created a procedure, just type its name to run all the instructions it contains.
A procedure has three parts:
to square The title line "to" and
the name of the procedure.
repeat 4 [fd 50 rt 90] Instructions.
end The last line.
All procedures must start with to and the name of the procedure. You choose the name, but always make sure that it doesn't contain any spaces. The name must be unique in the Procedures Tab in which the procedure is defined and it cannot be a name that exists in the MicroWorlds EX built-in vocabulary (primitives, object name, page name, etc.). Procedures must also end with the word end on its own line.
The example above is a simple procedure, without inputs. To use this procedure you only need to type its name in the Command Center, in a button's instruction field, or in other instruction fields in a turtle's backpack (OnClick, OnColor, etc.).
Here's an example of a procedure with an input. In this example, :size is an input. It is placed on the title line of the procedure, and it can be used where appropriate inside the procedure.
to square :size
repeat 4 [fd :size rt 90]
end
This version of the square procedure lets you draw squares of different sizes.
When using a procedure that requires an input, you must specify the value of its input when you run the procedure (just as you would specify the input for any primitive that requires one, such as forward or right).
A procedure can have several inputs.
A procedure name can be used just like a primitive. A procedure can even be used in another procedure, called a superprocedure. Here's an example of a superprocedure calling a subprocedure:
to house
square
fd 50 rt 30
triangle
lt 30 bk 50
end
to square
repeat 4 [fd 50 rt 90]
end
to triangle
repeat 3 [fd 50 rt 120]
end
The superprocedure house calls two subprocedures: square and triangle.