BSL:Introduction: Difference between revisions

contraindicating use of bools
m (opening wording)
(contraindicating use of bools)
Line 61: Line 61:


===Type specification===
===Type specification===
BSL does not support weak typing. You need to specify your types when making declarations, as seen in the above examples. You can choose from "bool", "int", "float" (rarely useful because of BSL's limited math operations), and "string". As with C, you use "void" to mean "no type" when defining functions.
BSL does not support weak typing. You need to specify your types when making declarations, as seen in the above examples. You can choose from "bool" (buggy, so not recommended), "int", "float" (rarely useful because of BSL's limited math operations), and "string". As with C, you use "void" to mean "no type" when defining functions.


===Conditional===
===Conditional===
Line 121: Line 121:


==Data types==
==Data types==
You can choose from "void", "bool", "int", "float", and "string" (with "void" only allowed when defining a function):
You can choose from "void", "bool", "int", "float", and "string" (with "void" only allowed when defining a function). The "bool" type is buggy in Windows Oni, so use of "int" is recommended instead.


func void something(void)
  var int a = 1;
  var int a = 1;
# see the "Functions" section below on how to use a data type keyword when defining a function


The "int" type is signed 32-bit. See the Manual's [[BSL:Manual#Data types|Data types]] section to learn about various limitations on math between different data types in BSL.
The "int" type is signed 32-bit. See the Manual's [[BSL:Manual#Data types|Data types]] section to learn about various limitations on math between different data types in BSL.


==Functions==
==Functions==
As mentioned above, functions do not need to be declared or defined before they are called. Defining and calling a function looks exactly like C, except for the "func" keyword:
As mentioned above, functions do not need to be declared or defined before they are called. Defining and calling a function looks exactly like C, except for the "func" keyword in the definition:


  a = get_enemy_count(false);<br />
  a = get_enemy_count(0);<br />
  func int get_enemy_count(bool count_dead)
  func int get_enemy_count(int count_dead)
  {
  {
     ...
     ...