BSL:Tutorial/Scratch
This page is a short tutorial on how to get started on simple scripts. It will teach you, step by step, how to write a simple script. By the end of this tutorial, you will be able to move on to more advanced scripts.
Part 1 : Knowing your formats
The game will accept 2 types of syntax for scripts, and they are based on different styles of writing. Choose the one that suits you best.
The types are :
Shell-Style: This is compiled much like some System-Shells. It is written in a "one-function-call-a-line" format, and is the easiest to begin with if you have had no coding experience, as the code is neatly displayed line after line. The downside of this it, that once you get into more complex scripts or scripts with many function calls, the file becomes very hard to read and very large.
Example: Shell-Style
C-Style: This is compiled much like the popular coding style C. The syntax can be placed into multiple-function lines and functions are divided by a ; . In advanced scripts, this style will allow you to condense your script and the parts will be easier to read/debug. It also allows you to utilse some of the more advanced features easily. The problem with this is, that starting off, it is harder to write if you have had no previous experience with coding.
Example: C-Style
For the purpose of this article, we will use Shell-Style syntax for simplicity.
Part 2: Starting Off
Now, I suggest reading the original script files to get a basic idea for how scripts are layed out. This will allow us to jump-start a bit.
Open up your IMGD and look for the following folder: EnvWarehouse. Open it up, and we'll take a look at how it it layed out. There should be several files in here. Open using NOTEPAD, the one titled warehouse_main.bsl. It should look like this:
func void main(void)
{
env_show 2010 0
gl_fog_blue=.15
gl_fog_red=.15
gl_fog_green=.15
gl_fog_start=.99
gs_farclipplane_set 5000
obj_create 20 20
level_start
}
This is an example of a main file. It contains the information of how the level starts.
Ignore the contents of the script for now, and notice that the contents of the function main are enclosed by a set of brackets ({ and }).
All functions must be enclosed in this set of brakets or it will not be executed.
Close the file, and rename the folder "EnvWarehouse" "EnvWarehouse_original". Then, create a folder called "EnvWarehouse" and create a script file inside and name it "Tutorial". We will be using this file to show various examples of scripts and finally, write a small script of your own.