BSL:Tutorial/Scratch: Difference between revisions

From OniGalore
Jump to navigation Jump to search
Line 89: Line 89:


MORE TO COME!
MORE TO COME!
Why isn't it in the OSL namespace???[[User:Geyser|geyser]] 06:04, 15 Nov 2005 (CET)
                                                               - Your_Mom
                                                               - Your_Mom

Revision as of 05:04, 15 November 2005

This page is a short tutorial on how to get started on simple scripts for those who have had no experience with scripting before. 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 utilize 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 laid 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 laid 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 brackets 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.



Part 3: Basic Commands

This is just a small section explaining the commands that will be used in this tutorial. For a complete list of commands, see Ssg's Site for more information.

ai2_spawn (name) - creates and starts an AI from a character object
chr_teleport (name) (flag) - teleports a character to a flag
chr_givepowerup (name) (powerup) (amount) - gives a character a powerup
. . .



Part 4: First Script

This section will teach you how to write a very basic arena script (fighting script). It will create an enemy for you to fight and teleport you to confront of him.

Let's open up our "Tutorial.bsl" file and start typing.

First, declare it the "main" portion of the script by typing "func void main(void) at the very beginning of the file. This tells the game which function it is. The "main" function is the function that the game looks at first to determine what is to be executed.

Below that line, type {. This tells the game that the function has started.

. . .

MORE TO COME!

Why isn't it in the OSL namespace???geyser 06:04, 15 Nov 2005 (CET)

                                                             - Your_Mom