You can imagine
variables as containener of number or text (strings). You can assig
values to variables, that are stored in computer memory, and later
recall that values by simply type the variables names.
For example:
' create variables
a = 2
b = 5
' use the previuosly created variables
c = a + b
Variable names can be any sequence of uppercase and lowercase letters and numbers.
There are only a few rules. Variable names must:
- begin with a letter;
- be different from reserved words like commands and internal constants;
- do not contain any embedded space, if a space is required use underscore ( _ ) character instead;
Example:
is wrong because it starts with a number. Following examples are correct:
player_1st = 1
player1 = 1
Example:
is wrong because bin is a command name. Following examples are correct:
bin2 = "some text"
binary = "some text"
Example:
is wrong because variable name is not continuous and contain a space. Following examples are correct:
alien_x = 100
alienX = 100
There are no types in sdlBasic; all variables and arrays are variants. This means that they can hold either numeric or string values. In general, sdlBasic will attempt to automatically cast a variable to the correct type.
For example: