19,397
edits
m (uhhhhhh oops) |
m (→Variables: brought in some points from BSL:Variables) |
||
Line 118: | Line 118: | ||
==Variables== | ==Variables== | ||
A variable is a storage space in memory for a value that you will want to access at different times, and perhaps change over time as well. | A variable is a named storage space in memory for a value that you will want to access at different times, and perhaps change over time as well. The name of the variable is expected to start with a letter, but it can contain numbers and the underscore (<code>_</code>) at any point after that. A variable name cannot be the same as one of BSL's [[#Reserved words|reserved words]], e.g. an int named "return", and obviously it cannot share a name with any built-in or declared function either. | ||
===Declaring=== | ===Declaring=== | ||
When declaring a variable, the statement must begin with "var" and the type of the variable... | When declaring a variable, the statement must begin with "var" and the type of the variable... | ||
var int i = 0; | var int i = 0; # declare a variable named "i" which starts with the value 0 | ||
You don't have to initialize variables (set them to a value when declaring them), but it's usually a good idea. If you don't initialize, the engine will use a default value: "false" for bools, "0" for ints and floats, and "" (an empty string) for strings. | |||
===Accessing=== | ===Accessing=== | ||
...but not when getting or setting its value later: | ...but not when getting or setting its value later: | ||
i = 4; | i = 4; | ||
if (i eq 0) | |||
[...] | |||
==Data types== | ==Data types== |