19,388
edits
m (→Variables: wording) |
(general copy-edit) |
||
Line 2: | Line 2: | ||
{{TOClimit|2}} | {{TOClimit|2}} | ||
==Files== | ==Files== | ||
When Oni loads a level, it also loads and parses all .bsl files in the folder in [[IGMD]] which contains that level's scripts (the name of | When Oni loads a level, it also loads and parses all .bsl files in the folder in [[IGMD]] which contains that level's scripts (the name of this folder being specified by the level's [[ONLV]] resource). Like C, the code automatically begins running at the time of level-load with the function called "main", regardless of which .bsl file it is found in (Oni's scripts always place it in a file called *_main.bsl). | ||
Unlike C, there are other "entry points" in the code. For instance, characters can call script functions upon death and trigger volumes can call functions when they are entered or exited. See [[CHAR]], [[OBD:BINA/OBJC/CONS|BINA CONS]], [[OBD:BINA/OBJC/DOOR|BINA DOOR]], [[NEUT]], and [[TRGV]] for all known places in the game data that can trigger BSL functions. | Unlike C, there are other "entry points" in the code. For instance, characters can call script functions upon death and trigger volumes can call functions when they are entered or exited. See [[CHAR]], [[OBD:BINA/OBJC/CONS|BINA CONS]], [[OBD:BINA/OBJC/DOOR|BINA DOOR]], [[NEUT]], and [[TRGV]] for all known places in the game data that can trigger BSL functions. | ||
Line 44: | Line 44: | ||
} | } | ||
Notice that parentheses are always needed with "if" statements and semicolons are always needed on variable declarations. Note that using the strong syntax avoids certain weird aspects of BSL (see the Manual's [[BSL:Manual#Old vs. new syntax|Old vs. new syntax]] section for details). | Notice that parentheses are always needed with "if" statements and semicolons are always needed on variable declarations. Note that using the strong syntax avoids certain weird aspects of BSL, and that mixing aspects of strong and weak syntax can cause errors (see the Manual's [[BSL:Manual#Old vs. new syntax|Old vs. new syntax]] section for details). | ||
===Comments=== | ===Comments=== | ||
Line 58: | Line 58: | ||
func int get_enemy_count(void) | func int get_enemy_count(void) | ||
Functions do not need to be defined or declared | Functions do not need to be defined or declared above the place in the code where they are called, unlike in C. | ||
===Type specification=== | ===Type specification=== | ||
Line 82: | Line 82: | ||
===Flow interrupt=== | ===Flow interrupt=== | ||
There is no "goto" statement in BSL, nor any loop controls like "continue" or "break" (since there are no proper loops!). There's a "return" keyword in BSL, but | There is no "goto" statement in BSL, nor any loop controls like "continue" or "break" (since there are no proper loops!). There's a "return" keyword in BSL, but a "return" inside of an "if" statement will fire regardless of whether the statement evaluates to true or false. So you only use "return" to return data at the end of the function, not to exit early (see the [[#Functions|Functions]] section). | ||
There's also a "sleep" command that pauses BSL execution; you pass it a number in ticks: | There's also a "sleep" command that pauses BSL execution; you pass it a number in ticks: | ||
Line 89: | Line 89: | ||
===Loop=== | ===Loop=== | ||
There's no loop keyword like "for" or "while" in BSL, but you can kind of get a loop using one of two methods. First, you can call a function recursively, but BSL has a short stack, so don't expect to get more than four levels deep. If you just want a loop and not recursion, then you can avoid recursion and the related stack limitation by "sleep"ing for a tick or more, and then "fork"ing the call that would otherwise be recursive. See [[BSL:Snippets]] for an example that also makes up for the missing | There's no loop keyword like "for" or "while" in BSL, but you can kind of get a loop using one of two methods. First, you can call a function recursively, but BSL has a short stack, so don't expect to get more than four levels deep. If you just want a loop and not recursion, then you can avoid recursion and the related stack limitation by "sleep"ing for a tick or more, and then "fork"ing the call that would otherwise be recursive. See [[BSL:Snippets]] for an example that also makes up for the missing multiplication operator in BSL. | ||
Second, you could use schedule-repeat-every: | Second, you could use schedule-repeat-every: | ||
Line 95: | Line 95: | ||
schedule some_function() repeat 50 every 20; | schedule some_function() repeat 50 every 20; | ||
Just be aware that the BSL will continue executing without waiting for this loop to finish. | ...or schedule-at: | ||
schedule some_function() at 15; | |||
schedule some_function() at 30; | |||
schedule some_function() at 45; | |||
... | |||
Just be aware that the BSL will continue executing without waiting for this loop to finish. Also, there is no way to exit the loop early, but some_function() could simply refuse to perform its task if a global variable has changed to false, simulating a loop exit. | |||
===Multi-threading=== | ===Multi-threading=== | ||
Line 114: | Line 121: | ||
==Data types== | ==Data types== | ||
You can choose from "void" | You can choose from "void", "bool", "int", "float", and "string" (with "void" only allowed when defining a function): | ||
func void something(void) | func void something(void) | ||
var int a = 1; | var int a = 1; | ||
The "int" type is signed 32-bit. See the Manual's [[BSL:Manual#Data types|Data types]] section to learn about various limitations | 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== | ||
Line 147: | Line 154: | ||
==Built-in functions and variables== | ==Built-in functions and variables== | ||
Like any game, Oni provides access to a number of hardcoded functions and global variables that can be used to | Like any game, Oni provides access to a number of hardcoded functions and global variables that can be used to alter the game environment. They are listed on [[BSL:List]], and grouped by common task in the [[:Category:Scripting tasks|Scripting tasks]] category. | ||
[[Category:BSL docs]] | [[Category:BSL docs]] |