BSL:Manual: Difference between revisions

488 bytes removed ,  7 December 2015
making a separate section for explaining built-ins, as on BSL:Introduction
(scope bug confirmed; consistent strong syntax in examples; example for "!" operator)
(making a separate section for explaining built-ins, as on BSL:Introduction)
Line 488: Line 488:


==Functions==
==Functions==
A function is a block of code that can be accessed repeatedly whenever you want to perform a certain task. As in mathematics, functions can be passed input and can return output, though unlike in mathematics, they do not need to do either of those things in order to be useful, as functions can affect external data by modifying global variables and by calling built-in functions which affect the game environment.
A function is a block of code that can be accessed repeatedly whenever you want to perform a certain task. As in mathematics, functions can be passed input and can return output, though unlike in mathematics, they do not need to do either of those things in order to be useful, as BSL functions can affect external data by modifying global variables and by calling built-in functions which affect the game environment.
 
===Built-in vs. script-defined===
There are two classes of functions: script-defined and built-in.
 
====Built-in====
Built-in functions such as "ai2_allpassive" are hardcoded into Oni, that is, they were defined in C along with the rest of the engine code and then registered as accessible to BSL scripts, so you will not find their code in any game script -- only calls made to them. Built-in functions are listed on [[BSL:Reference]]. Guidance on how to use them is found in the [[:Category:Scripting tasks|Scripting tasks]] category. You can manually call from the developer console any built-in function.
 
====Script-defined====
You can manually call from the developer console any functions you declared in a script, however, you cannot actually define functions through the console.


===Defining===
===Defining===
Line 639: Line 630:
==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 storage space in memory for a value that you will want to access at different times, and perhaps change over time as well.
===Built-in vs. script-defined===
There are two classes of variables: script-defined and built-in.
====Built-in====
Built-in variables are hardcoded into Oni, that is, they were declared in C along with the rest of the engine code and then registered as accessible to BSL scripts, so you will not find them declared in any game script. The built-in variables are listed on [[BSL:Reference]]. Guidance on how to use them is found in the [[:Category:Scripting tasks|Scripting tasks]] category. You can get and set the value of any built-in variable from a script or from the developer console.
====Script-defined====
You can use the [[Developer Mode|developer console]] to get and set the value of a global variable that you declared in a script, but you cannot actually declare variables through the console.


===Declaring===
===Declaring===
Line 659: Line 641:
  i = 4;
  i = 4;
  var int c = i;
  var int c = i;
==Built-in functions and variables==
The above documentation for functions and variables explains how to create your own functions and variables. But, like any game, Oni provides access to a number of built-in functions and variables; these are used to write level scripts in BSL.
Built-in functions and variables such as "ai2_allpassive" and "ai2_blind" are hardcoded into Oni, that is, they were defined in C along with the rest of the engine code and then registered as accessible from BSL. This means that they are essentially [[wikipedia:Black_box|black boxes]]: you are only given an external description of the input they take and the outcome of this input, but you cannot see the actual code behind them.
When using the developer console, you can manually call a built-in function, and can get and set the value of a built-in variable. However, you cannot actually define functions or declare variables through the console.
Built-in functions and variables are listed on [[BSL:Reference]]. They are grouped together by subject matter in the [[:Category:Scripting tasks|Scripting tasks]] category.


[[Category:BSL docs]]
[[Category:BSL docs]]