Every variable in Blitz must have a type, so Blitz knows what can be stored in that variable. A type in Blitz is represented
by using a postfix (i.e. variable.<type>) on the variable name, with the postfix showing what type the variable is. There are six built-in types
in Blitz, and are capable of storing textual or different types of numeric data. The types are as follows:
| Type | Postfix | Description |
| Byte | .b | A byte type is used for storing numeric data, and takes up 1 byte of memory (hence the name). You can store integers (i.e. whole numbers, no fractions) in the range -128 to +127 in a byte. |
| Word | .w | The word type is also used for storing numeric data (the name comes from the term 'word size' when applied to CPUs). It takes up 2 bytes in memory, allowing you to store integers in the range -32,768 to +32,767. The way that Blitz creates executables, this is the fastest variable type to use for numeric data. |
| Long | .l | Long (aka longword) is also a type for holding numeric data. This type of variable uses 4 bytes in memory and can store values in the range -2,147,483,648 to +2,147,483,647. |
| Quick | .q | A quick type is the first type of numeric variable which allows you to store numbers with a fractional part. Despite it's name, it is not too fast when used in calculations (it is the same speed as a long type, but faster than a float). Each quick variable uses 4 bytes of memory and can store numbers in the range -32768 and +32767.9999847412109375 and is accurate to 0.0000152587890625, although you'll probably never see that many digits :) |
| Float | .f | The second type of numeric type which can be used to store fractional values is the float. This is so called because it uses floating point mathematics (but it does not use the FPU, even if you have one!), allowing you to store very large numbers and also very small fractions. Be careful though, as when you mix very large numbers and small fractions, the accuracy will be that of the large numbers and so you may 'lose' the fractional values (e.g if you add 235 to 0.1 you'll get 235 due to the accuracy used). |
| String | .s | The only textual data type built into Blitz is the string. A string always requires 4 bytes plus each character uses one byte of memory and is represented by the ASCII value for that character. All strings in Blitz are terminated with a null byte (it has a value of 0). Instead of the '.s' postfix, you can use the dollar sign '$', but you must keep the same postfix as you defined the variable with. |
All the numeric types in Blitz are said to be signed, because they can store a positive and negative
range of numbers. From the above table, we can see that a variable with a word type could be referred
to as e.g. "foo.w". The next section explains how to go about
defining and using variables in Blitz.
|