Jump to content

BSL:Manual: Difference between revisions

m
→‎Variables: didn't realize that we broke up the flow of the "… …" series with that interpolated remark on initialization
m (added hovertext defining BFW)
m (→‎Variables: didn't realize that we broke up the flow of the "… …" series with that interpolated remark on initialization)
Line 121: Line 121:


===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; # declare a variable named "i" which starts with the value 0
  var int i = 0; # declare a variable named "i" and initialize it to 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.
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:
After a variable has been declared, you don't use "var" or the type of the variable when getting or setting its value:


  i = 4;
  i = 4;