Topic 7 - Saving and Loading Your Functions

Start with an empty Work window (select everything and press the Delete key to remove it). Enter the following functions into the Work window (you can use copy):

TO SQUARE
REPEAT 4 [FD 50 RT 90]
END

TO HEXAGON
REPEAT 6 [FD 40 RT 60]
END

TO OCTAGON
REPEAT 8 [FD 40 RT 45]
END

Now save your work in a file called 'SHAPES'. To do this select the File menu and click on the Save option. Find the Drives list on the right hand side of the dialogue box and change the drive to N: (your user area). Enter a file name (SHAPES.LOG - replace the '*') and click on the OK button.

Your work is now saved. To open it next time use the File menu again and the Load option. Each time you open some stored functions you will have to press Enter after each END in a function to activate it (look for the message in the Text box).

To test your save you should close Logo, open it again and use File/Load to open your file of functions.

To use a function you will have to move the cursor to the end of each line containing 'END' (after the 'D') and press 'Enter'. This will bring up a message in the Text window like 'You have defined SQUARE'.

Create a new function called 'MANYPOLY' and call the three functions you have defined:
TO MANYPOLY
SQUARE HEXAGON OCTAGON
END

This shows that you can call functions from within functions (and also functions within functions within functions...).

Note that you can use the blue and red disk buttons in the Toolbar to perform Load and Save operations.

Exercise: Traffic Lights

We now have the techniques we need to design some traffic lights.

You will design some functions to do the following:

You can then create a function to control these functions in a sequence, for example:

TO TRAFFICLIGHTS
REDPOSITION
REDLIGHTON
AMBERPOSITION
AMBERLIGHTON
REDAMBEROFF
GREENLIGHTON
END

You could also place the functions inside a REPEAT structure:

REPEAT 1000 [REDLIGHTON AMBERLIGHTON REDLIGHTOFF AMBERLIGHTOFF GREENLIGHTON]

This is as far as you need to go.

Copy and paste your functions into a Word document and save it (then you can copy the functions back to an empty Work window and save them as a Logo file without all the mistakes and extra lines).

Solution

Return to Logo Home Page