LOGO Basic bannerLOGO Basic banner

All the applications we use require input from us as users from time to time. The input could be clicking the bold button in Microsoft Word or typing a value into an Excel workbook. The input data is then processed according to the instructions in the app you are using.

Starting point

The final version of the code in the tutorial Variabilize a program in LOGO is as follows:

make "numberOfSides 4
make "lengthOfSides 100

repeat :numberOfSides [   
	fd :lengthOfSides  
	rt 360/:numberOfSides  
]

readword is a great introduction to the JOption class in Java.

To change the variables, we must change the code each time. This is far from ideal and impossible for the user to do in compiled programs such as Java. I think we can also agree it is poor form to expect our users to modify our programs!

Runtime!

The next step involves refactoring the code so that the user is asked to input the parameters at run-time. For this, we use the readword command. While the syntax for the command is super simple, it needs to be used in conjunction with the make command to assign the input value to a variable so that it can be used later in your program:

make "numberOfSides (readword [ Enter number of sides: ] )

Visit our LOGO cheatsheet here!

Whatever is typed between the square brackets will appear as text to prompt the user. The user’s input is then assigned to the variable numberOfSides.

Screenshot of the readword text input dialog in Turtle Academy.
Screenshot of the readword text input dialog in Turtle Academy.

Put it all together

All together now:

make "numberOfSides (readword [ Enter number of sides: ] ) 
make "lengthOfSides (readword [ Enter length of sides: ] )  

repeat :numberOfSides [   
	fd :lengthOfSides  
	rt 360/:numberOfSides  
]

References:

  1. Turtle Academy. (2023) Lessons. Available at: https://turtleacademy.com/lessons/23 (Accessed: 28 January 2023)
  2. Terrapin. (No date) Commands Overview. Available at: https://resources.terrapinlogo.com/weblogo/commands/ (Accessed: 22 April 2024).

By MisterFoxOnline

Mister Fox AKA @MisterFoxOnline is an ICT, IT and CAT Teacher who has just finished training as a Young Engineers instructor. He has a passion for technology and loves to find solutions to problems using the skills he has learned in the course of his IT career.

2 thought on “Get some user input in LOGO”
  1. This seems to be a very useful site for searching out more details on using Logo. However, I have not been able to get the variable input for ‘readword’ to work.
    In my program I have written ‘make “xStreet ( readword [Enter X Position: ] )’
    The result is an error message ‘unexpected object [Enter X Position: ]’
    I need user input in my program – preferably without having to set up files containing my required inputs!
    I am using ACSLogo on MacOS 15.2 Sequoia.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.