lghelp4.txt171010720540109021033060446803023020456456verdana 10verdana 12verdana 12 underscoreMs_Sans_Serif 11LOGOScript HelpOkWelcome to LOGOScript v.4LOGOScript is a simple scripting language designed primarily to program basic turtle graphics.

Write your own code and run it through the "Run" menu to see the results.

To learn about different keywords and syntax, look up the relevant topic.



LOGOScript has been written by UncleBen.
Its syntax is supposed to be similar to the LOGO language. Still, it is a dialect of it and code written in other dialects of LOGO may not run correctly in this program.General syntaxEach statement in LOGOScript begins with a keyword. If the keyword requires any parameters, these must be written after the keyword in the order the program expects them to be.
Parameters are numeric. Each parameter may be either a literal value (e.g 12) or variable (e.g :age).
Variable names are preceeded by a colon ( : ).
Other structures are:
    - code blocks, placed inside square brackets [ ], that are used with REPEAT, IF and IFNOT commands.
    - mathematical operations and evaluations, placed inside round brackets ( ). There must not be any spaces in the brackets and only two values with one operator may be entered. These are used with the EQUALS, IF and IFNOT keyword.
    - literal string expressions, placed inside double quotes " ". The closing quote must not be preceeded by a space. These are used with the PRINT and ASK keywords.

LOGOScript is not a case-sensitive language (except for literal strings), therefore FORWARD and forward is the same.
Each word must be separated by a space / line break (except mathematical operations and evaluations).
You may write several statements on one line or break up a statement over many lines.
Comments begin with two slashes ( // ). The rest of the line is not executed."Hello World!"Although LOGOScript is meant for turtle graphics, it has the PRINT command to print text and/or variables to the text editor.

Code for "Hello World" in LOGOScript would be:

          PRINT "Hello World!"

For more about the PRINT command, see the "Input/Output" section.Turtle commandsPENDOWN or PD - lowers the drawing pen.
PENUP or PU - raises the drawing pen. Nothing will be drawn as the turtle moves.
PENSIZE x or PS x - sets the size of the pen to x. Let x have a larger value to draw thicker lines.
NORTH - sets the direction of following movement towards north (straight up).

HOME, CENTRE or CENTER - places the pen to the centre of the graphics area.
PLACE x y - places the pen to x and y in the graphics area.
GOTO x y - moves the pen ti x and y in the graphics area, drawing a line if the pen is down.

FORWARD x or FD x - moves the pen forward in current direction by x pixels (dots).
RIGHT x or RT x - turns the pen right by x degrees.
LEFT x or LT x - turns the pen left by x degrees.Using coloursThere are two ways to set the colour of the drawing pen.
The first is the COLOUR or COLOR command, that lets you use the 16 Windows colours.

To set the colour of the pen to green, write:
          COLOUR green

Since each colour has a code number, you can use these codes to set the colour.
          COLOUR 11
   or
          COLOUR :a_colour

To fill the whole graphics area, first set the COLOUR and then write the FILL command:
          COLOUR red
          FILLList of coloursThe 16 colours together with the code number that can be used with COLOUR command are:

1 - black
2 - blue
3 - brown
4 - cyan
5 - darkblue
6 - darkcyan
7 - darkgray
8 - darkgreen
9 - darkpink
10 - darkred
11 - green
12 - lightgray
13 - pink
14 - red
15 - yellow
16 - whiteRGB coloursAlternatively you may set the pen colour using the RGB command. This command requires three parameters and lets you specify the RGB values of red, green and blue.

          RGB 128 128 255
   or
          RGB :red :green :blue

These values have to be in the range 0 - 255. If any of them gets smaller than 0, it is set to zero and a warning is printed to the execution text editor.

To fill the whole drawing area with a RGB colour, first set the colour:

          RGB 0 0 0 FILLUsing variablesVariables in LOGOScript can only hold numeric values and must always be preceeded by a colon ( : ). Unlike in earlier versions, variables need not be declared first. However, the program will not recognize variables that are used only in mathematical operations / evaluations.
Although you may assign non-integers to a variable, the program will round its value each time a variable is encountered.
All variables initially have the value 0. To assign a different value to a variable, use the EQUALS command.
           EQUALS 12 :var
   or
           EQUALS :x :var
The first statement sets the value of :var to 12, the second sets its value to the current value of variable :xMathematicsMathematics in LOGOScript basically means assigning the result of an arithmetic operation to a variable. Therefore another variant of the EQUALS command is used.

          EQUALS (5+:a) :b

This statement looks up the value of :a, adds 5 to it and stores the sum in variable :b.
To increment a variable by one, use

          EQUALS (:a+1) :a

Note that the mathematical operation is placed in rounded brackets and does not contain any spaces. Also keep in mind that only one operation may be applied to two values in one EQUALS statement. The last word of the statement must be the name of the variable to put the result in.

Examples of other operations are:
          EQUALS (:a-:b) :c
          EQUALS (:x*:x) :x
          EQUALS (:a/2) :b

Note that the results are always rounded.Random numbersYou can get random integers with the RANDOM command.

This command takes three parameters:
   - the minimum value
   - the maximum value
   - name of the variable, where the random integer will be stored.

          RANDOM 4 12 :x

This statement picks a random integer between 4 and 12 (inclusive) and stores it in variable called :x.

You can also use variables:

          RANDOM :min :max :randomInput and outputUse the ASK command to get numeric input from the user.
It has two forms.

           ASK :var
brings up a prompt dialog with the text "Enter value for variable :var"

You can also change the text, using a literal string:

           ASK "How old are you?" :age

Use the PRINT command to print text and / or values of a variable to the execution texteditor.

Three combinations are available:

          PRINT "Hello"   - prints Hello
          PRINT "Size is" :size - prints (e.g) Size is 10
          PRINT :size   - prints 10

Use PRINT "" to print an empty line.

Note that there must not be a space before the closing quote.LoopsLOGOScript enables you to put some code in a loop.

          REPEAT x [statement1 statement2]

This line repeats statement1 and statement2 x times. The REPEAT command is followed by a value or variable saying how many times the loop is to be executed. Code to be repeated is placed inside square brackets. The list of statements may continue over several lines of code and you may leave a space before and after the brackets.

This code draws a square:

          REPEAT 4 [
          FORWARD 100 RIGHT 90 ]

It is also possible to put another REPEAT loop inside a loop. In this case, however, make sure that there is a space between the two closing brackets:

          REPEAT x [statement1 REPEAT y [statement2] ]IF and IFNOTIF and IFNOT lets the program execute or skip a block of code if a condition evaluates to true or false respectively.

The syntax is following:
    keyword is followed by an evaluation statement (in rounded brackets, similar to the EQUALS operation) and the block of code in square brackets.

As with EQUALS command, only two values can be compared using the "=", "<" or ">" signs.

Example:

          IF (:a=100) [PRINT ":a equals 100]
          IFNOT (:a=100) [PRINT ":a does not equal 100]

As with loops, do not let several closing square brackets follow each other immediately - put a space between them.Defining new keywordsThe greatest feature of LOGO language is that it lets you define your own keywords. Instead of writing out all the statements needed to draw, for example, a square, you can define a new SQUARE keyword and use it in the main program instead.

The definition of a new keyword starts with TO that is followed by the name of the new keyword. After that type the commands needed to draw this object. The end of the definition must be signalled by the END keyword.
For an example, see the next chapter.

Always place the keyword definitions at the beginning of the code. Also, since a definition by itself should not be executed, you'll have to signal the beginning of the main code with the BEGIN keyword.Example of defining a SQUAREThis is an example how to define and use a SQUARE keyword:

          TO square    //start definition of SQUARE
          REPEAT 4 [FD :length RT 90] //rules for the square
          END    //end definition

          BEGIN   //beginning of the main program
          PENDOWN HOME NORTH
          ASK "How big will the square be?" :length
          SQUARE    //draws the squareUsing the keyword libraryIf you want to use a keyword you have defined in several programs, you don't have to define it in all the programs. Instead you may write a file containing just the keyword definition and save it as a "*.kwd" file in the "library" folder (choose "Save keyword" in the "File" menu). To use it in a program, you must first include it using the INCLUDE keyword. This keyword should be at the beginning of the code and the beginning of the main program should be signalled with the BEGIN keyword.

Example (assuming there is a file called "square.kwd" in the "library" folder):

          INCLUDE square

          BEGIN  //main code starts here
          PENDOWN HOME NORTH
          ASK "How big will the square be?" :length
          SQUARE

If the INCLUDEd keyword uses variables, you have to know what they are, in order to pass values to the objects. Use the "Keyword help" menu option. This opens a dialog listing the used variables and displays the code.Error logIf there are any coding errors in your code, any encountered errors are reported in the execution texteditor. Although coding errors should not crash LOGOScript, the program may not work as expected.

Possible sources of errors are:
   - typing mistakes
   - omitting the colon in variable names
   - syntax errors, wrong number of parameters for a command.
   - closing quotes preceeded by a space
   - not leaving a space between two closing brackets

Error messages:
   - include a - file not found (the included object does not exist)
   - invalid parameter (interpretor expects a variable but does not recognize it)
   - unknown operator (interpretor is unable to interpret a mathematical operation / evaluation)
   - bad colour parameter (either a spelling mistake in a COLOUR statement or the code number is not from 1 to 16)
   - rgb value less than 0 (as it says)
   - I don't know how to a (the interpretor expects a keyword but does not recognize it.)
