Variables
A variable is a named place to keep a value that can change, such as a score or a position. Give it a value with =, and use its name wherever you need the value:
score = 0score = score + 10Print "Score: " + score
A variable comes into being the first time it is used, and until it is given a value, it holds 0, 0.0, an empty string or Null, depending on its type.
Types
Every variable holds one kind of value, set by the tag on its name where it is first used: none or % for an integer, # for a float, $ for a string, or .TypeName for an object (see Identifiers). After that the tag can be left off: speed# = 2.5 then speed = speed * 2. A name can only have one type, so using x as an integer and then x# as a float is an error. Values of another kind are converted on the way in (see Basic Data Types).
Local and global variables
A variable belongs to the place it is made in. One made in the main program can only be seen by the main program; one made inside a function can only be seen inside that function, and is made fresh, empty, each time the function is called. So functions can use names such as i or count without upsetting each other or the main program.
To share a variable between the main program and every function, declare it with Global, outside any function, before using it:
Global lives = 3, playerName$ = "Ann"Function LoseLife() lives = lives - 1 If lives = 0 Then Print playerName$ + " is out!"End Function
Local declares a variable that belongs to the current function, or the main program, on purpose, even if a global has the same name. It is never needed otherwise, but it makes the intention clear. Both Global and Local can give a starting value, and both can declare several variables at once, separated by commas.
