Blitz Basic / AmiBlitz generally uses syntax common to most dialects of BASIC. Line numbers are not used; instead, each line in the source file is executed in turn starting from the top. Lines are entered as with any text editor, and moving to a different line either by using the arrow keys, clicking the mouse, or pressing Enter, tells Blitz to scan the line and detect any keywords for highlighting.
Variables are assigned a value using a single equals sign. For example:
a = 10
b = a + 5
In this example, a contains the value 10 and b contains the value 15.
In AmiBlitz 3, keywords by default will be highlighted as follows:
- Built-in keywords are highlighted in blue
- Built-in keywords that access the custom chips are highlighted in red (these will only work when running on classic Amiga hardware or an emulator)
- Comments are highlighted in green italics
- Constants are highlighted in magenta
- Procedures (statements and functions) are highlighted in green
- String constants are highlighted in grey
Commands built into Blitz are keywords that are entered to carry out a specific action. They may accept parameters or arguments which are entered after the keyword and separated by a comma if more than one argument is required. Brackets are not used around the arguments. For example:
The Plot command plots a single pixel on the currently used bitmap, and it takes 3 arguments. The first is the X coordinate, the second is the Y coordinate, and the third is the colour in which to draw the pixel. So, this example draws a single pixel 20 pixels across and 30 pixels down using pen 2 on the current bitmap.
Functions are similar to commands except they return a value to your program, which means you must do something with the value even if you don't need it. To differentiate from commands, arguments to functions need to be enclosed in brackets. For example:
a = Abs(-25)
The Abs function calculates and returns the absolute value of its argument, in this case 25. The value returned is stored in the variable a. The return value can also be used directly as a parameter in another function or statement, for example:
NPrint "The absolute value of -25 is ", Abs(-25)
This example uses the result of the Abs function as the second argument of the NPrint command. NPrint then displays the message followed by the result of the Abs function.
Comments are extra text entered in your code that aren't part of the program itself but are used to make notes within your code. Blitz follows the same convention as AmigaDOS in using the semicolon character to mark the start of a comment. The comment ends at the end of the line. For example:
- Calculate the Absolute value of variable a
b = Abs(a)
- Now tell everyone
Nprint "Absolute value of ", a, " is ", b
Comments can be added after the end of a line if desired:
Plot x, y, 3 ; Drawing colour 3 at the coordinates x,y
Comments are optional, but highly recommended! In a simple program they might not seem necessary, but once your code gets longer and more complicated, comments can help enormously when you try to understand what you were doing previously. They're even more important if there's ever a possibility that someone else will work on your code!