| Wave's~ BlitzMax Tutorial | ~ July 20, 2005 ~ Version 10 |
| Beginners guide to BlitzMax | version 7 |
| Variables | |
|
You probably know this: A variable is a place where you may store a number or a text. There are different variable "types" depending on their use. Here are the most basic types: Integers which store numbers, Strings which store text and Floats which store decimal numbers.We also have object-"types" which includes these basic types such as Arrays, Lists and your own custom Types (more on these later). See the Language Reference if you want more information about BlitzMax variables. If you want to increase a variable, let say speed. You can write Speed = Speed + Acceleration Or in a shorter way Speed:+Acceleration. Both are identical, but the last is shorter. It is strongly recommended but not required that you declare your variables before use. | |
|
Local Speed:
Float=0
, Acceleration:Int
, Name:String
= "Name" Local Speed#= 0 , Acceleration , Name$ = "Name" | |
|
These 2 lines are identical; use whatever you like, but be aware of both. Note:Local is a way to declare the variable. Note: If you want to force all variables to be declared by you, use the command Strict which gives you a compile error if there is a variable that you didn't declare like this: Local/Global VarName:VarType , 2ndVarName:VarType. | |
| Example: | |
| Local Name$ = "-=[ Fireglue ]=-" | |
|
I do not use Strict in my examples, so if you want to use strict make sure you declare all my variables. You should always use Strict unless you are very lazy or are making a tiny examples or minor tests, it will help you find misspelling-bugs before they occur and save you hours of debugging. Note: BlitzMax considers Speed and speed and sPeEd to be the SAME variable. | |
| Same goes with all commands. | |
| Like rem or Rem or reM. | |
| Global or Local | |
|
A variable can be Global or Local. Globals can be accessed from the entire program. Locals on the other hand are more complicated, cause where they exists depends on where they where declared. To declare a local variable use the keyword Local in front of the variable name. If you declare a local variable in a function it will only exist in that function. If it is declared in a loop if will only exists as long as you are in that loop. If a local is in an if-statement it will only exists in that if-statement. | |
| Constants | |
| You can also declare constants. A constant will have the value you gave it when you first declared it. The value of a Constant can never change, it will always stay the same. If you try to change a constant'a value the complier will warn you when you compile - build. Constant is useful for values that always will stay the same. You'll encounter constants in examples later on. | |
| To Index | Next Page | page 3 |