Blitz:General Syntax

From Amiga Coding
Revision as of 16:30, 23 July 2015 by Daedalus (talk | contribs) (Labels)
Jump to: navigation, search

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


Statements are 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: Plot 20,30,2 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 statements 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. Note that these functions are different to procedures that return values (also called functions).


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 also be added after the working part 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!


Labels allow you to jump to or identify segments of your code. They are used as the targets for Goto and Gosub statements, as well as more advanced techniques such as determining the address of a segment of code in memory. Labels are created by entering the name of the label at the start of a line. Each label must be unique, and it is considered good practice to end the label with a colon, for example: MyLabel: Optionally, a dot can be added at the start of the label. This indicates to the editor that the label should be added to the list of shortcuts in the side navigation bar of the editor screen. For example: .MyLabelThis is very convenient, as it allows you to click on a label to move the editor directly to its location. Neither the colon nor the dot count as part of the actual label, so it is still referenced as MyLabel in both of the above examples.